Cannot read packageName from AndroidManifest.xml

前端 未结 14 1082
情歌与酒
情歌与酒 2020-12-15 19:52

I have errors in my android manifest file:

Error:Cannot read packageName from C:\\Users\\brandon\\AndroidStudioProjects\\MineDodge2\\app\\src\\main\\AndroidM         


        
相关标签:
14条回答
  • 2020-12-15 20:18

    Your second <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" /> are not allowed here. I think ` < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.brandon.MineDodge" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/redjet"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.brandon.MineDodge.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    
        <activity
            android:name="com.example.brandon.MineDodge.Splash" />
    </application>
    

    ` That will be OK.

    0 讨论(0)
  • 2020-12-15 20:18

    I had this in a multi-subproject project, caused by the subproject not matching the configure( clause in the top-level build.gradle.

    Specifically I had

    configure(subprojects.findAll { it.name.startsWith("pachymeninx") }) {
    

    which did not match my new subproject called pachymen. But the Gradle build process issued no warning (that I saw) and instead gave "Cannot read packageName from AndroidManifest.xml" error for the pachymen subproject.

    0 讨论(0)
  • 2020-12-15 20:24

    In response to Eldar Kurbanov who had this error in Unity & anyone else who finds this question after having the error when building with gradle in Unity.

    This is not a Unity 2018 'bug' nor is it caused by something being missing from the Manifest pre-build. It's actually caused by the mainTemplate.gradle file missing the line:

    applicationId '**APPLICATION**'
    

    Inside the defaultConfig {} block of the android {} section. This will ensure the generated manifest has the package name inserted into it.

    Yes manually inserting the package name into the main manifest will work, but it's much better to just use Unity's project settings to set the package name rather than hard-coding it.

    If anyone else finds this question and they're using Unity then here's an example mainTemplate.gradle you can use for referencing: https://pastebin.com/hPs0uvkZ

    0 讨论(0)
  • 2020-12-15 20:28

    The android:name="com.example.brandon.MineDodge.MainActivity" should be under <application>, not under <activity>.

    0 讨论(0)
  • 2020-12-15 20:30

    If you are using an old version of build.grade file, you should remove this code:

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

    Then, Build > Clean Project

    Note: If you see this code, you are using the old version

    0 讨论(0)
  • 2020-12-15 20:37

    Check if your src file is named with some different name.....if thats the case then you might end up with this error....rename it to "src

    0 讨论(0)
提交回复
热议问题