AndroidStudio 开发过程中遇到的常见的编译问题

  1. butterknife 引用没问题出现nullpoint问题
butterknife的导入必须放在library module。

那么如何解决呢?解决方法很简单,在 app module 内引用 annotationProcessor

 annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
 而在 library  module内引用 butterknife 即可解决。

compile 'com.jakewharton:butterknife:8.8.1'

  1. Gradle sync failed: Cause: com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List
插件冲突
先删除插件逐步排查处理
  1. 编译错误不提示信息使用以下指令查看信息
查看错误 编译信息
./gradlew :app:compileYijiedaiDebugJavaWithJavac  --stacktrace

./gradlew compileDebug --stacktrace

./gradlew -q dependencies app:dependencies --configuration compile
  1. compile 与 Implementation、api引用区别
Implementation引用有时候会出现依赖工程无法加载相应的包

在3.0版本中,compile 指令被标注为过时方法,而新增了两个依赖指令,一个是implement 和api,这两个都可以进行依赖添加,但是有什么区别呢? 
api 指令

完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。 
implement指令

这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开
  1. Ndk x86_64等找不到
mac上使用brew 代替 apt-get
 //在终端分别运行下面两条指令,安装lib32stdc++6  和lib32z1
 sudo apt-get install lib32stdc++6
 sudo apt-get install lib32z1
  1. lintOptions 参数含义
 android {
     lintOptions {
         // true--关闭lint报告的分析进度
         quiet true
         // true--错误发生后停止gradle构建
         abortOnError false
         // true--只报告error
         ignoreWarnings true
         // true--忽略有错误的文件的全/绝对路径(默认是true)
         //absolutePaths true
         // true--检查所有问题点,包含其他默认关闭项
         checkAllWarnings true
         // true--所有warning当做error
         warningsAsErrors true
         // 关闭指定问题检查
         disable 'TypographyFractions','TypographyQuotes'
         // 打开指定问题检查
         enable 'RtlHardcoded','RtlCompat', 'RtlEnabled'
         // 仅检查指定问题
         check 'NewApi', 'InlinedApi'
         // true--error输出文件不包含源码行号
         noLines true
         // true--显示错误的所有发生位置,不截取
         showAll true
         // 回退lint设置(默认规则)
         lintConfig file("default-lint.xml")
         // true--生成txt格式报告(默认false)
         textReport true
         // 重定向输出;可以是文件或'stdout'
         textOutput 'stdout'
         // true--生成XML格式报告
         xmlReport false
         // 指定xml报告文档(默认lint-results.xml)
         xmlOutput file("lint-report.xml")
         // true--生成HTML报告(带问题解释,源码位置,等)
         htmlReport true
         // html报告可选路径(构建器默认是lint-results.html )
         htmlOutput file("lint-report.html")
         //  true--所有正式版构建执行规则生成崩溃的lint检查,如果有崩溃问题将停止构建
         checkReleaseBuilds true
         // 在发布版本编译时检查(即使不包含lint目标),指定问题的规则生成崩溃
         fatal 'NewApi', 'InlineApi'
         // 指定问题的规则生成错误
         error 'Wakelock', 'TextViewEdits'
         // 指定问题的规则生成警告
         warning 'ResourceAsColor'
         // 忽略指定问题的规则(同关闭检查)
         ignore 'TypographyQuotes'
     }
 }
  1. 过滤包重复
//configurations.all {
//    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
//        def requested = details.requested
//        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
//            if (requested.name.startsWith("appcompat-v7")) {
//                details.useVersion '26.1.0'
//            }
//        }
//    }
//}
  1. 检查依赖编辑错误
 gradle build --stacktrace
 #查看包依赖冲突
首先点开界面右边的Gradle,找到项目名–Task–Android–androidDependencies,右键选择Run…………

9.com.android.dex.DexException: Multiple dex files define的解决办法

搜到的方式有很多,原因主要是多个module依赖了共同的jar包

解决的方式是
a. 在project下面建立一个libs目录
b. 将A module 下libs目录中的a.jar移动到上一步中创建的目录中 并修改编译脚本
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile fileTree(dir: '../libs', include: '*.jar')
}
将B module 下libs目录中的a.jar删除掉 并修改编译脚本
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile fileTree(dir: '../libs', include: '*.jar')
}
--------------------- 
原文参考:https://blog.csdn.net/voo00oov/article/details/49931175 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值