使用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下

最终会生成以下目录

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,908评论 25 708
  • 发热放入Android6.0带来了新的权限管理方式,根据提供的官方文档,再加上自己的理解,做了以下汇总仅供大家伙参...
    PapiAP阅读 1,748评论 0 6
  • 那么,我们先定一个小目标,比如每天500万? 不,不,不,是我打错了,500字。 要是每天500万,我不是忙着花钱...
    99小鱼9999阅读 407评论 0 2
  • 已经入伏天,温度基本在35左右和以上,还会不时有雷雨,肉肉们还活着,真开心。不过难的还在后头,今年伏天约40天,越...
    肉米米阅读 767评论 0 0
  • 我手头只有256M的Zero(H2+),参考了一些别人的想法,然后试图自己构建OP,基于Armbian的内核和驱动...
    不着调的小男生阅读 3,435评论 0 1