10

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

Robert Ruxandrescu
  • 627
  • 2
  • 10
  • 22

3 Answers3

8

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.

aaronvargas
  • 12,189
  • 3
  • 52
  • 52
  • I actually do have an aar library in my project. Interesting. I'm at home now and I can't check it out, but it's very likely that you are right. – Robert Ruxandrescu Oct 14 '17 at 22:32
3

I had a category element in my Manifest file inside a regular activity which was causing build failure. removing it after updating to as3-rc1 and build tool 26+ my issue was resolved. Hope this helps someone.

    <activity
        android:name=".AboutUsActivity"
        android:label="@string/title_activity_about_us"
        android:parentActivityName=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <category android:name="android.intent.category.DEFAULT" />

        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.MainActivity" />
    </activity>
habla2019
  • 93
  • 1
  • 9
1

if problem remains, please check this official tutorial on migrate to Gragle plugin v. 3.0.0.

Got the same error, in my case there was typo in meta_data instead of meta-data in the Manifest file preventing a build.

Goltsev Eugene
  • 3,325
  • 6
  • 25
  • 48