自从Google发布AS 3.0以来,一直都在犹豫要不要升级,要不要升级,要不要升级!昨天手贱升级了之后,呵呵哒!前方无数个坑慢慢爬吧,仅以记录自己遇到的关于AS 3.0来发过程中遇到的问题和解决方法。
1.错误如下
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
解决办法
在项目的gradle.properties中加入:
android.enableAapt2=false
2.关于library依赖
图片.png背景:
build.gradle(module:library):
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
build.gradle(module:app):
buildTypes {
release {
signingConfig signingConfigs.myconfig
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
greendao {
schemaVersion 2
}
}
原因:app中buildTypes集合不是library的buildTypes集合子集,即app中buildType属性greendao在依赖的library中找不到。
解决办法:
在build.gradle(module:library)增加greendao
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
greendao{
}
}
3.关于多渠道打包错误
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=xiaomiDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
之前的打包方式:
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
File outputDirectory = new File(outputFile.parent);
def fileName
if (variant.buildType.name == "release") {
fileName = "app_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
} else {
fileName = "app_v${defaultConfig.versionName}_${releaseTime()}_debug.apk"
}
output.outputFile = new File(outputDirectory, fileName)
}
}
}
修改成下面的方式:
applicationVariants.all { variant ->
variant.outputs.all {
if (variant.buildType.name == "release") {
outputFileName = "app_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk"
} else {
outputFileName = "app_v${defaultConfig.versionName}_${releaseTime()}_debug.apk"
}
}
}
4.错误如下
Error:Execution failed for task :app:processDebugAndroidTestResources.
> No slave process to process jobs, aborting
解决办法
clean和rebuild都没有成功后,直接点击 File>Invalidate Caches/Restart后编译通过
5.错误如下
Error:(12, 32) 错误: 程序包android.support.multidex不存在
解决办法
在build.gradle文件里加上compile 'com.android.support:multidex:1.0.1'即可
6.错误如下
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved
versions for app (26.1.0) and test app (27.1.1) differ.
See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
解决办法
android {
...
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
dependencies {
...
}
7.错误如下
Vivo Oppo系列手机运行安装总是失败
Failure [INSTALL_FAILED_TEST_ONLY]
解决办法
图片.png
在该处加入
...
#解决Vivo手机安装失败问题
android.injected.testOnly=false
8.全面屏适配
//在Manifest的application节点加入属性
<application
...
android:resizeableActivity="true"
tools:targetApi="n"
.../>
...
<!--适配全面屏手机-->
<meta-data android:name="android.max_aspect"
android:value="2.1"/>
...
9.依赖
错误如下
Error: Could not find common.jar (android.arch.core:common:1.0.0).
Searched in the following locations:https://jcenter.bintray.com/android/arch/core/common/1.0.0/common-1.0.0.jar
解决办法 将google()
放在最前面
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
10.导入项目错误
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
解决办法
android {
...
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
}
...
}
网友评论