Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with AndroidManifest.xml in Android Studio 3.0 [duplicate]

I recently installed Android Studio 3.0 from the Canary channel. However, loading my old projects, this keeps on popping up in the AndroidManifest.xml file that's automatically generated depending on the build variant:

Error:(49) unknown element <uses-sdk> found

This also is displayed:

Error:/home/computername/AndroidStudioProjects/applicationname/app/build/intermediates/manifests/full/release/AndroidManifest.xml:49 unknown element <uses-sdk> found

Needless to say, this wasn't an issue in Android Studio 2.3. Any ideas on how to solve this? I've read a handful of similar issues here but none solved my problem. By the way - it doesn't matter if I set the build variant to debug or release, it says the same thing. Also, the "R" class doesn't work, and if I hover over the manifest xmlns:android="http://schemas.android.com/apk/res/android declaration, it says "URI is not registered".

Again, the project structure hasn't changed at all, I've only upgraded to Android Studio 3.0.

Thanks!

Here's the AndroidManifest.xml file that is under the /src/main folder, which works perfectly fine. The problem is with the generated AndroidManifest.xml files in the /app/build/intermediates/manifests/full folder - THESE are the ones that break my app.

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.domain.appname">`

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".view.MainActivity"
                android:noHistory="true">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".view.TabbedActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar"
                android:screenOrientation="landscape"
                android:configChanges="keyboardHidden|orientation|screenSize"
                android:noHistory="true">

            </activity>
        </application>

        <!-- PROTECTION_NORMAL permissions, automatically granted -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />

        <!-- DANGEROUS PERMISSIONS, must request -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    </manifest>

Here's the way the debug or release auto-generated Manifests that don't work look like:

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

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="25" />

    <!-- PROTECTION_NORMAL permissions, automatically granted -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- DANGEROUS PERMISSIONS, must request -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <meta-data
        android:name="android.support.VERSION"
        android:value="25.3.1" />

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.domain.appname.view.MainActivity"
            android:noHistory="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.domain.appname.view.TabbedActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:label="@string/app_name"
            android:noHistory="true"
            android:screenOrientation="landscape"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>

        <uses-sdk
            android:minSdkVersion="21"
            android:targetSdkVersion="25" />
    </application>

</manifest>

Later edit

I've went back to Android Studio 2.3, and set the gradle plugin back to 2.3.2, and here's how the automatically generated AndroidManifest.xml looks like now:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.domain.appname.test" >

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="26" />

    <instrumentation
        android:name="android.support.test.runner.AndroidJUnitRunner"
        android:functionalTest="false"
        android:handleProfiling="false"
        android:label="Tests for com.domain.appname"
        android:targetPackage="com.domain.appname" />

    <application>
        <uses-library android:name="android.test.runner" />
    </application>

</manifest>

Now everything works as usual, however, note the difference between the automatically generated Manifest file under gradle 3.0.0 and the one under gradle 2.3.2

I guess I'll have to wait until someone finds a solution to make this work under gradle 3.0.0 and in the meantime use the gradle plugin 2.3.2 in Android Studio 3.0 (which I'm doing right now and it works).

So the issue is with the new gradle 3.0.0-alpha9

like image 481
Robert Ruxandrescu Avatar asked Aug 07 '17 12:08

Robert Ruxandrescu


People also ask

How do I change AndroidManifest XML?

Open your Android project and go to <AppProjectFolder>/app/src/main/. Open the app manifest file AndroidManifest. xml and add the following lines to the file as child elements of the <manifest> element. Note: You must include the QUERY_ALL_PACKAGES permission if your app targets Android 11 (API Level 30) or higher.

Where is the AndroidManifest XML file in Android Studio?

Every project in Android includes a Manifest XML file, which is AndroidManifest. xml, located in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements.

What is the AndroidManifest XML file and why do you need this?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

What is contained in the AndroidManifest XML?

The Android App Manifest contains information about an Android application. Each application has a single Android App Manifest XML file at the root of the source set called AndroidManifest. xml .


1 Answers

You probably have a dependency library (aar) that has a <uses-sdk> inside the application tag in the manifest. So when that gets merged, your app will have the incorrect usage also.

This happened to me with an old local build of vlc for Android.

like image 146
aaronvargas Avatar answered Oct 05 '22 23:10

aaronvargas