安卓注解找不到AndroidManifest.xml文件

5

我查看了一些不同的问题,但是它们都没有给我提供有效的解决方案。我正在使用Android Annotations开发一个项目,当我尝试构建我的项目时,它会失败并出现以下错误(Project_Location只是我的本地项目文件夹):

错误:在指定路径中找不到AndroidManifest.xml文件:[/Project_Location/mobile/build/intermediates/manifests/full/debug/AndroidManifest.xml]

这是我的mobile build.gradle文件:

apply plugin: 'com.android.application'

ext.androidAnnotationsVersion = '3.3.2';
ext.eventBusVersion = '2.4.0';

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apply plugin: 'android-apt'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    wearApp project(':wear')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    compile "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    apt "de.greenrobot:eventbus:${eventBusVersion}"
    compile "de.greenrobot:eventbus:${eventBusVersion}"
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.dev.app_name"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "0.3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

configurations {
     apt
}

apt {
    arguments {
        androidManifestFile variant.outputs.processResources.manifestFile
        resourcePackageName 'com.dev'
    }
}

 android.applicationVariants.each { variant ->
    aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
    println "****************************"
    println "variant: ${variant.name}"
    println "manifest:  ${variant.processResources.manifestFile}"
    println "aptOutput:  ${aptOutput}"
    println "****************************"

    variant.javaCompile.doFirst {
        println "*** compile doFirst ${variant.name}"
        aptOutput.mkdirs()
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.apt.getAsPath(),
                '-AandroidManifestFile=' + variant.processResources.manifestFile,
                '-s', aptOutput
        ]
    }
}

如果build.gradle文件看起来很混乱,我已经尝试多种解决方案但都没有成功。如果有冗余的声明可以被删除,请随时提供这些建议。现在,我只是困惑为什么它无法定位我的清单文件,而该文件明显存在。

重新构建项目? - piotrek1543
@piotrek1543 该错误出现在项目构建期间。 - John Riley
选择清理,然后重新构建 - 它应该重新生成它们。 - piotrek1543
1个回答

4

我修复了你的构建脚本,现在应该可以正常使用AndroidAnnotations:

apply plugin: 'com.android.application'

ext.androidAnnotationsVersion = '3.3.2';

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

dependencies {
    apt "org.androidannotations:androidannotations:${androidAnnotationsVersion}"
    compile "org.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.dev.app_name"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "0.3"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
        resourcePackageName "com.dev.app_name" // the same as package in the manifest
    }
}

更新:使用annotationProcessor代替apt

android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": "com.dev.app_name"]
            }
        }
    }
}

请确保您正在使用最新版本的AndroidAnnotations。


这个建议很有用!在这里稍加调整后,我的项目成功构建了。谢谢,这让我感到非常疯狂。 - John Riley
apt插件自Android Studio起已被弃用,现在该如何使用它? - nAkhmedov
请查看维基:https://github.com/androidannotations/androidannotations/wiki/Building-Project-Gradle - WonderCsabo
1
apt已经过时了,@WonderCsabo我正在使用android studio 3.2 canary 17,我也遇到了这个问题,上面的解决方法并没有起作用。 - Zulqurnain Jutt
我更新了我的答案,并添加了新语法的片段。 - WonderCsabo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接