其他分享
首页 > 其他分享> > Android Annotations找不到AndroidManifest.xml

Android Annotations找不到AndroidManifest.xml

作者:互联网

我已经检查了几个不同的问题,但没有一个提供适合我的解决方案.我正在使用Android Annotations开发一个项目,当我尝试构建我的项目时,它失败并出现以下错误(Project_Location只是我的本地项目文件夹):

error: Could not find the AndroidManifest.xml file in specified path : [/Project_Location/mobile/build/intermediates/manifests/full/debug/AndroidManifest.xml]

这是我的移动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文件看起来像一团糟,我已经尝试实现多个解决方案但没有成功.因此,如果有可以删除的冗余语句,也可以随意提供这些建议.现在,我只是难以理解为什么它找不到我明确存在的清单文件.

解决方法:

我修复了构建脚本,它应该适用于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.

标签:android,android-manifest,android-gradle,build-gradle,android-annotations
来源: https://codeday.me/bug/20190523/1156709.html