如何解决 Android Studio 找不到项目的 Manifest 文件的错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22356181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:52:04  来源:igfitidea点击:

How to resolve the Android Studio error where it cannot find the project's Manifest file?

androidandroid-studioandroid-gradle-pluginbuild.gradle

提问by Fergers

I am migrating my legacy project from Eclipse to Android studio. I did the following things:

我正在将我的旧项目从 Eclipse 迁移到 Android Studio。我做了以下几件事:

  • Export and generate gradle build files in eclipse
  • Imported the Gradle.build file in Android Studio
  • Changed my gradle version dependencies to: classpath 'com.android.tools.build:gradle:0.9.+'
  • 在eclipse中导出和生成gradle构建文件
  • 在 Android Studio 中导入 Gradle.build 文件
  • 将我的 gradle 版本依赖项更改为:classpath 'com.android.tools.build:gradle:0.9.+'

My root folder of the project contains 3 library projects: Actionbarsherlock, Authbahnand library. My root folder also contains the main project called JohelpenHulpverlener.

我的项目根文件夹包含 3 个库项目:ActionbarsherlockAuthbahnlibrary。我的根文件夹还包含名为JohelpenHulpverlener的主项目。

enter image description here

在此处输入图片说明

After resolving a lot of errors I get the following error:

解决了很多错误后,我收到以下错误:

Error:A problem was found with the configuration of task ':checkDebugManifest'.
> File 'C:\android\jeugdformaat\JohelpenHulpverlener\AndroidManifest.xml' specified for property 'manifest' does not exist.

My root build.gradle looks like this:

我的根 build.gradle 看起来像这样:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(":actionbarsherlock")
}

android {
    compileSdkVersion 17
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

My build.gradle in the main project looks like this:

我在主项目中的 build.gradle 如下所示:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':library')
    compile project(':actionbarsherlock')
    compile project(':autobahn')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

I am trying to understand this, hopefully someone can help me out here!

我正在努力理解这一点,希望有人可以帮助我!

回答by Scott Barta

You've got a bunch of stuff in your root-level Gradle build file that's making the build system think there's an Android module there (it's not; it's a subdirectory below inside JohelpenHulpverlener) , and it's failing because it's not finding the manifest.

你的根级 Gradle 构建文件中有一堆东西,这让构建系统认为那里有一个 Android 模块(它不是;它是JohelpenHulpverlener下面的一个子目录),它失败了,因为它没有找到清单。

I think if you take a lot of stuff out of your root-level build.gradlefile and replace it with the default version for new projects, which is this:

我想如果你从根级build.gradle文件中取出很多东西并将其替换为新项目的默认版本,那就是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

it will work.

它会起作用。

回答by Umesh

In build.gradlefile specify package name like

build.gradle文件中指定包名称,如

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"


defaultConfig {
    applicationId "com.myapp"
    minSdkVersion 11
    targetSdkVersion 19
    versionCode 27
    versionName "1.5.6"
}
}

applicationId "com.myapp"Here "com.myapp" is packagename of my app. I hope this will help you.

applicationId "com.myapp"这里“com.myapp”是我的应用程序的包名。我希望这能帮到您。

回答by ElectronicGeek

Make sure you have tags on the outside like this:

确保你在外面有这样的标签:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example"
    android:versionCode="1"
    android:versionName="1.0" >

    ...

</manifest>

回答by Amar

I had the same problem when migrating eclipse project to android studio. The problem is that the root Gradle build file created by android studio is wrong and it should be like this :

将 eclipse 项目迁移到 android studio 时,我遇到了同样的问题。问题是android studio创建的根Gradle构建文件是错误的,应该是这样的:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Update : It seems the problem has been fixed by Android Studio's latest version 1.4, now we can easily import eclipse project into studio

更新:Android Studio 的最新版本 1.4 似乎已经解决了这个问题,现在我们可以轻松地将 eclipse 项目导入到 Studio 中

回答by raghu.tjm

Build->Rebuild solved it for me.

Build-> Rebuild 为我解决了它。

回答by user5031270

I know this is an old post, but I helped a friend who is new to programming with this problem last night. Your suggestions were examined but did not apply. Their last action before the error was to add a list view layout to the project. I asked them to delete it and the errors vanished after a few moments.

我知道这是一个旧帖子,但我昨晚帮助了一个不熟悉编程的朋友解决这个问题。你的建议已经过,但没有适用。他们在错误之前的最后一个操作是向项目添加列表视图布局。我要求他们删除它,几分钟后错误就消失了。

I have not found any other post with this scenario and this conclusion so I thought sharing it here might help someone else.

我还没有找到任何其他关于这个场景和这个结论的帖子,所以我认为在这里分享它可能会帮助其他人。

Conclusion: Adding a new component to the wrong place may be another reason for such an error.

结论:将新组件添加到错误的位置可能是导致此类错误的另一个原因。