升级gradle
首先按照提示升级了gradle版本
gradle-wrapper.properties文件中gradle版本改为4.3
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip
对应Project的build.gradle中的gradle插件版本改为3.0.0,还有在repositories中添加google()
classpath 'com.android.tools.build:gradle:3.0.0'
repositories {
google()
mavenCentral()
jcenter()
maven { url 'https://dl.bintray.com/growingioreactnative/maven/' }
}
同步后提示buildToolsVersion版本要求26.0.2
buildToolsVersion = "26.0.2"
再同步又各种报错
报错一:
The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin. Perhaps you misspelled something?
问题出在一个module的build.gradle中有一句
instrumentTest.setRoot('tests')
应该是新版的gradle弃用了instrumentTest方法,用androidTest代替即可
androidTest.setRoot('tests')
再同步后报警告
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
这句很好理解,只是api和implementation到底用哪个?
api 指令
完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。
implement指令
这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开
参考:
http://www.it1352.com/139247.html
https://blog.csdn.net/soslinken/article/details/73114637
https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph
报错二:
报错
All flavors must now belong to a named flavor dimension.
这句百度了下,解决方法各不相同,用了最简单一种
在主项目的build.gradle的defaultConfig中添加一句
flavorDimensions "default"
报错三:
报错
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':tangram'.
> Could not resolve all files for configuration ':tangram:classpath'.
> Could not resolve com.android.tools.build:gradle:2.3.3.
Required by:
project :tangram
> Could not resolve com.android.tools.build:gradle:2.3.3.
> Could not get resource 'http://oss.jfrog.org/oss-snapshot-local/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom'.
> Could not HEAD 'http://oss.jfrog.org/oss-snapshot-local/com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom'. Received status code 409 from server:
在浏览器点开链接报错409
{
"errors": [
{
"status": 409,
"message": "The repository 'oss-snapshot-local' rejected the resolution of an artifact 'oss-snapshot-local:com/android/tools/build/gradle/2.3.3/gradle-2.3.3.pom' due to conflict in the snapshot release handling policy."
}
]
}
说是oss-snapshot-local仓库拒绝了gradle-2.3.3.pom的加载,打开tangram这个module的build.gradle,repositories中有引入了oss-snapshot-local库,把这句注释掉再编译就好了,不知道有没有更好的办法
// maven { url "http://oss.jfrog.org/oss-snapshot-local/" }
报错四:
项目有用react native写,编译提示
nable to resolve dependency for ':MPLib@debug/compileClasspath': Could not resolve com.facebook.react:react-native:+.
于是指定了具体版本
com.facebook.react:react-native:0.53.3
报错五:
还有个报错是说Mainifest中不能指定minSdkVersion,忘了截图了
那就把这句删了就好咯
报错六:
项目可以编译成功了,但是有些代码爆红,在调用静态方法的地方提示
cannot access android.support.v4.app.BaseFragmentActivityDonut
这个是v4包版本太低了,我直接换成了26
compile 'com.android.support:support-v4:26.0.0'
再次编译,不爆红了
打包遇到问题
报错一:
java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource compilation failed
原因是因为android studio3.2是默认把AApt2开启的
解决方法
gradle.properties文件中添加一句
android.enableAapt2=false
报错二:
The same input jar is specified twice
Warning:Exception while processing task java.io.IOException: The same input jar […….jar] is specified twice.
解决方法
将混淆文件proguard-rules.pro中所有的-libraryjars 注释掉,变成 #-libraryjars xxxx.jar
原因分析
build.gradle文件已经配置了
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
}
里面已经添加过jar包,sdk 通过 proguard 混淆代码时默认已经将 lib目录中的 jar 都已经添加到打包脚本中,所以不需要再次手动添加。
参考:
https://blog.csdn.net/ylbf_dev/article/details/50448727