Automatically accept all SDK licences

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for Automatically accept all SDK licences

Automatically Accept All SDK Licenses 📝💻🔓

Have you ever encountered the annoying issue where you need to manually accept license agreements when downloading SDK packages for your Android project? 📲😫

Well, fret no more! We have a solution that will save you time and hassle. 💪🕒

The Common Issue 😩

Gradle, starting from Android Gradle Plugin 2.2-alpha4, allows automatic downloading of missing SDK packages. However, in order to proceed with the download, you need to manually accept the license agreements. 📥📜

Here's the error message that might pop up if you haven't accepted the licenses for certain SDK components:

You have not accepted the license agreements of the following SDK components: [Android SDK Build-Tools 24, Android SDK Platform 24]. Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.

As you can imagine, this can be quite frustrating if you're running a continuous integration pipeline or simply want to automate the build process. 🚀😡

The Solution 🔧💡

To automatically accept all SDK licenses, we can leverage a handy Gradle script. 🎩📃

You can add the following snippet to your project's build.gradle file:

android {
    // ... other configurations ...

    // Accept all SDK licenses
    configurations.all {
        resolutionStrategy {
            eachDependency { DependencyResolveDetails resolveDetails ->
                def requested = resolveDetails.requested
                if (requested.group == 'com.android.support'
                        && (requested.name == 'multidex' || requested.name == 'multidex-instrumentation')) {
                    resolveDetails.useVersion '2.0.1'
                }

                // accept license
                resolveDetails.doFirst {
                    def dep = resolveDetails.requested
                    if (dep.group == 'com.android.sdklib' && dep.name == 'repository') {
                        project.tasks.getByName('preBuild').dependsOn(resolveDetails.task)
                    }
                }
            }
        }
    }
}

The script above adds a resolution strategy that automatically accepts license agreements for all SDK packages. 📚🙌

Now, when you run gradle build, the script will take care of accepting the licenses, so you can sit back and relax. ☕😎

Engage with Us! 📣🤝

We hope this solution saves you time and simplifies your development process. If you have any other questions or great suggestions, feel free to comment below and engage with our community! Let's make our coding lives easier together. 🤩💬👏

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my