gpt4 book ai didi

android - 当我将 AspectJ 应用于带有 Androidannotations 的 Android 项目时不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:44:33 35 4
gpt4 key购买 nike

我正在使用 Androidstudio 0.8.9 并使用 gradle 构建。

我使用的是 Android-Annotations,效果很好。我也想使用 AspectJ,所以应用插件(https://github.com/uPhyca/gradle-android-aspectj-plugin)。

但是编译失败,并抛出一些错误信息

:app:compileDebugJavaInternal compiler error: java.lang.IllegalStateException: java.lang.IllegalArgumentException: Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183):app:compileDebugAspectj FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:compileDebugAspectj'.> Internal compiler error: java.lang.IllegalStateException: java.lang.IllegalArgumentException: Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 13.616 secsUnknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager.discoverNextProcessor(BatchAnnotationProcessorManager.java:183)2:04:32: External task execution finished 'build'.

My build.gradle is

repositories {
mavenCentral()
}

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.+'
}
}

def androidAnnotationsVersion = '3.1';
def daggerVersion = '1.0.0';

apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'
apply plugin: 'android-apt'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "com.flask.aspectjtest"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}

configurations {
apt
ajc
aspects
ajInpath
}

apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName "com.flask.aspectjtest"
}
}

ext.aspectjVersion = '1.8.2'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'

apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
}

所以,我测试了 aspectj 插件单独工作(没有 android-annotations),并且运行良好。我找到了一些答案(Android Annotations and MonkeyTalk?),FAQ Page of AA .但我认为这是 eclipse 解决方案,我无法用这个答案解决我的问题。

我将注释处理器 android-apt 更改为 ajc。但是现在,它找不到 AndroidManifest.xml 文件。 (因为apt配置不可用)

repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
}

buildscript {
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.+'
}
}

def androidAnnotationsVersion = '3.1';
def daggerVersion = '1.2.2';

apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "com.flask.aspectjtest"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']
resources.srcDirs = ['src/main/resources']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
}

configurations {
ajc
aspects
ajInpath
}

ext.aspectjVersion = '1.8.2'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'

ajc "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
ajc "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
}

现在,

:app:generateDebugSources UP-TO-DATENote: Resolve log file to /Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/androidannotations.logNote: Initialize AndroidAnnotations 3.1 with options {}Note: Start processing for 2 annotations on 13 elementserror: Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644771646)Note: Time measurements: [Whole Processing = 10 ms], [Extract Annotations = 7 ms], [Extract Manifest = 2 ms], Note: Finish processingNote: Start processing for 0 annotations on 0 elementsNote: Time measurements: [Whole Processing = 0 ms], Note: Finish processing1 error:app:compileDebugJava FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:compileDebugJava'.> Compilation failed; see the compiler error output for details.* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 3.596 secsCompilation failed; see the compiler error output for details.10:19:31: External task execution finished 'build'.

androidannotations.log 如下。

10:17:30.890 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:84 - Initialize AndroidAnnotations 3.1 with options {}10:17:31.58 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:108 - Start processing for 2 annotations on 13 elements10:17:31.77 [Daemon Thread 2] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644651076)10:17:31.78 [Daemon Thread 2] INFO  o.a.p.TimeStats:81 - Time measurements: [Whole Processing = 19 ms], [Extract Annotations = 15 ms], [Extract Manifest = 2 ms],10:17:31.78 [Daemon Thread 2] INFO  o.a.AndroidAnnotationProcessor:122 - Finish processing10:19:31.568 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:84 - Initialize AndroidAnnotations 3.1 with options {}10:19:31.637 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:108 - Start processing for 2 annotations on 13 elements10:19:31.647 [Daemon Thread 3] ERROR o.a.h.AndroidManifestFinder:134 - Could not find the AndroidManifest.xml file, going up from path [/Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug] found using dummy file [] (max atempts: file:///Users/flask/Documents/workspace_android/AspectJTest/app/build/intermediates/classes/debug/dummy1412644771646)10:19:31.648 [Daemon Thread 3] INFO  o.a.p.TimeStats:81 - Time measurements: [Whole Processing = 10 ms], [Extract Annotations = 7 ms], [Extract Manifest = 2 ms],10:19:31.648 [Daemon Thread 3] INFO  o.a.AndroidAnnotationProcessor:122 - Finish processing

最佳答案

而不是 AspectJ 插件 - com.uphyca.gradle:gradle-android-aspectj-plugin' 尝试使用 https://github.com/Archinamon/GradleAspectJ-Android用于 dagger+aspectj 插件集成。

首先将 Maven 存储库链接添加到模块构建文件的存储库 block 中:

maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' }

将插件添加到构建脚本的依赖项部分:

classpath 'com.archinamon:AspectJ-gradle:1.0.15'

应用aspectj插件:

apply plugin: 'com.archinamon.aspectj'

现在构建您的项目并运行。

关于android - 当我将 AspectJ 应用于带有 Androidannotations 的 Android 项目时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26199972/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com