在Android studio 3.1.2上编译报错AAPT2 error:check logs for details.
在网上搜索一般的解决方法都是在gradle.properties文件里添加一行android.enableAapt2= false就行了,但是按照这种方法修改后我的编译又会报出“ Process 'command 'E:\Android\Sdk\build-tools\27.0.1\aapt.exe'' finished with non-zero exit value 1 ”这个问题,所以我就没有继续尝试这种方法。
然后我就重新回去看报错的detail log,一个错误一个错误的看,看到报错
错误检索父项︰ 没有找到资源,匹配给定名称 ' android : TextAppearance.Material.Widget.Button.Bord
你所编译的SDK版本必须匹配支持库,所以倒回去看gradle.properties文件
是这样的(注意添加下划线的三行)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.example.wd.flashlight"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
可以看到匹配的库为25
implementation 'com.android.support:appcompat-v7:25.1.1'
所以我们我们将
compileSdkVersion 25
targetSdkVersion 25
都修改为25
修改完成后再重新编译,可以看到就没有再继续报aapt2 error的错误了,而是报代码本身的错误了(如下图)
之后再继续解决代码的报错问题。
关于aapt报错的问题暂时还不确定是不是真的得到了解决,只是用这篇文章来记录在实践过程中遇到的问题,之后有进展再继续更新。
转载请注明出处!