使用gradle打包安卓时报 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的错误解决方法

从Android Gradle plugin 2.2.0开始,gradle会自动加载需要的SDK, build-tools,但是因为没有接受权限更新,导致加载依赖终止,提示

Failed to notify project evaluation listener. > You have not accepted
the license agreements of the following SDK components: [Android
SDK Build-Tools 25.0.3]. 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.
Alternatively, to learn how to transfer the license agreements from
one workstation to another, go to [http://d.android.com/r/studio
ui/export-licenses.html](http://d.android.com/r/studio-ui/export
licenses.html) > Must apply 'com.android.application' first!

创建license

在终端中执行以下三条命令,记得是在android sdk 的目录下面

mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

license存放在$ANDROID_HOME/licenses下

最终会生成以下目录

使用gradle打包安卓时报 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的错误解决方法_第1张图片
WechatIMG26.jpeg

使用Jenkins的配置安卓的自动打包时也会有这个问题,因为Android SDK需要更新,而没有权限,所以会报这个错,加入这个后。Jenkins就有了自动更新的权限,然后就会自动下载需要更新的安装包。
执行

mkdir -p "$ANDROID_SDK/licenses"

可能报没有权限Permission denied,加上sudo,然后输入密码就行了

sudo  mkdir -p "$ANDROID_SDK/licenses"

接着执行

echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

这时候一样会报没有权限Permission denied,对刚创建的licenses文件夹root一下

chmod -R 777 + licenses的path

这样就可以了。如果实在搞不定的话分享我的给你吧[链接: https://pan.baidu.com/s/1hsOkPb2 密码: s9a2]
下载然后放在Android SDK的目录下就好了。

最后stackoverflow上面的解决方案
https://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences

你可能感兴趣的:(使用gradle打包安卓时报 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的错误解决方法)