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.
