问题
运行 weex build android 命令时出现如下错误:
BUILD FAILED in 2s
at checkExecSyncError (child_process.js:601:13)
at Object.execSync (child_process.js:641:13)
at C:\Users\feng\.xtoolkit\node_modules\weexpack\lib\build\android.js:156:20
at new Promise (<anonymous>)
at buildApp (C:\Users\feng\.xtoolkit\node_modules\weexpack\lib\build\android.js:152:10)
at <anonymous>
Error: Error: Command failed: call gradlew.bat assembleRelease
isLibProject: false, isAppProject: true
weex_plugin: []
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:javaPreCompileRelease'.
> Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- weexplugin-processor-1.3.jar (com.taobao.android:weexplugin-processor:1.3)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
原因
工程依赖了 weexplugin-processor 的 jar 包,而 jar 包里面用到了注解。在新的 gradle 版本里,需要写新的 groovy 代码来对每个引用注解的地方单独配置。
解决办法
1.在 platforms\android\app\build.gradle 文件中,使用 javaCompileOptions
defaultConfig {
applicationId "com.weex.app"
minSdkVersion project.appMinSdkVersion
targetSdkVersion project.targetSdkVersion
versionCode 1
versionName "1.0.0"
ndk {
abiFilters "x86"
abiFilters "armeabi"
}
//添加了javaCompileOptions
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
2.在 platforms\android\app\build.gradle 文件中,使用 annotationProcessor
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.taobao.android:weex_sdk:0.16.0'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-ws:2.3.0'
compile 'com.squareup.okio:okio:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile "com.alibaba:fastjson:${project.fastjsonLibVersion}"
compile "com.android.support:support-v4:${project.supportLibVersion}"
compile "com.android.support:appcompat-v7:${project.supportLibVersion}"
compile "com.android.support:design:${project.supportLibVersion}"
compile "com.android.support:support-annotations:${project.supportLibVersion}"
compile 'com.taobao.android:weex_inspector:0.10.0.5'
compile 'com.journeyapps:zxing-android-embedded:3.4.0'
// PLUGIN GRADLE EXTENSIONS START
compile 'com.taobao.android:weexplugin-loader:1.3'
compile 'com.taobao.android:weexplugin-processor:1.3'
//添加了annotationProcessor
annotationProcessor 'com.taobao.android:weexplugin-processor:1.3'
compile 'com.taobao.android:weexplugin-annotation:1.3'
// PLUGIN GRADLE EXTENSIONS END
}
此时出现如下错误:
* What went wrong:
Could not resolve all files for configuration ':app:releaseAnnotationProcessorClasspath'.
> Could not find com.alibaba:fastjson:1.1.27-android.
Searched in the following locations:
- file:/F:/Android/SDK/extras/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- file:/F:/Android/SDK/extras/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- file:/F:/Android/SDK/extras/google/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- file:/F:/Android/SDK/extras/google/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- file:/F:/Android/SDK/extras/android/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- file:/F:/Android/SDK/extras/android/m2repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- file:/C:/Users/feng/.m2/repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- file:/C:/Users/feng/.m2/repository/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- https://jcenter.bintray.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- https://jcenter.bintray.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- https://repo.maven.apache.org/maven2/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- https://repo.maven.apache.org/maven2/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- https://mvnrepository.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- https://mvnrepository.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
- https://maven.google.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.pom
- https://maven.google.com/com/alibaba/fastjson/1.1.27-android/fastjson-1.1.27-android.jar
Required by:
project :app > com.taobao.android:weexplugin-processor:1.3
从问题中可以发现,此时无法加载 com.alibaba:fastjson:1.1.27-android 依赖。下载依赖(网址),然后将其放在 C:\Users\feng.m2\repository\com\alibaba\fastjson\1.1.27-android 目录下即可,如图
推荐使用方案2,因为错误提示中,说明 javaCompileOptions 方法之后可能被删除!
参考:
1.Mr.Smile填坑记——AndroidStudio3.0 Canary 8注解报错Annotation processors must be explicitly declared now.
2.Annotation processors must be explicitly declared now…
3.Could not find com.alibaba:fastjson:1.1.27-android #8