AndroidStudio(Gradle)日常问题汇总持续更新

先写在前面,相信很多android er都碰到过不少gradle的坑,但是不得不说,gradle还是很强大的,写代码难免爬坑,还在用Eclipse的朋友们真的得早点换了。

下面是我和身边朋友碰到过的gradle的常见的问题和解决方案,会持续更新,虽然平时还是挺忙的,但是我会尽量做到不太监。

  • 1.打包时报the same input jar is specified twice
    解决:
混淆文件中删除-libraryjars libs/***.jarfrom your proguard-rules.pro file.
  • 2.Duplicate files copied in APK META-INF/DEPENDENCIES
    解决:
build.gradle中添加如下代码
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
  • 3.android studio加载不到so文件
    解决:
sourceSet.main中添加 jniLibs.srcDirs= ['libs']
  • 4.终端输入./gradlew提示 bash: ./gradlew : Permission denied
    解决:
chmod 777 ./gradlew
  • 5.终端命令./gradlew assemble时候报错,Caused by:org.gradle.api.InvalidUserDataException: File specified for property ‘signingConfig.storeFile’ does not exist.
    解决:
build.gradle中配置的signingConfig中的key地址不对
  • 6.终端命令./gradlew assemble时候报错,com.android.builder.packaging.SigningException: Failed to read key from keystore
    解决:
检查build.gradle中配置的signingConfig中的alias和password是否正确
  • 7.de.greenrobot.dao.DaoException: Could not init DAOConfig
    解决:
混淆文件中添加greenDao的混淆
-keepclassmembersclass * extends de.greenrobot.dao.AbstractDao {
    public static java.lang.String TABLENAME;
}
-keepclass **$Properties
  • 8.AndroidStudio2.0正式版项目build failed,console里报错your project contains non-asicII characters
    解决:
本地项目路径中包含中文,把项目所在的目录名改为英文即可
  • 9.AndroidStudio在小米手机上run不起来,报install_failed_canceled_by_user
    解决:
小米手机安全中心的问题,设置-更多应用-安全中心,点击卸载更新,然后就可以运行了。应该是安全中心最新的更新包,导致run不起来
  • 10.could not find com.android.support.constraint-layout
    解决:
在工具栏选择 Tools --> Android --> SDK Manager,勾选上 Support Repository中 的 ConstraintLayout for Android 和 Solver for 
  • 11.some file crunching failed see logs for d
    解决:
module的build.gradle中,在android{}中新增aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false

-12.release-stripped.ap_’ specified for property ‘resourceFile’ does not exist.
解决:

设置buildTypes里的release的shrinkResources为false即可,如果是 release-stripped.ap_' specified for property 'resourceFile' does not exist.则设置buildTypes里的debug的shrinkResources为false
    原文作者:nixoul
    原文地址: https://www.jianshu.com/p/a2b890a47008
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞