Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Android Studio read (minSdkVersion from) AndroidManifest.xml correctly?

I have an Android project which was created in Eclipse, exported as Gradle build file, then opened in Android Studio. (Yes, it would be far easier to create a clean project in AS but I need to support the current project structure.)

Otherwise things are now mostly working, but there's still some stuff to be ironed out. In every Activity class, AS shows this error: Class requires API level 1 (current min is -1): Activity

enter image description here

Alt+Enter offers to fix that with a @TargetApi annotation... but why should I have to do that, when in AndroidManifest.xml, we have:

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

AndroidManifest.xml is located at project root (Eclipse default?). Looks like Android Studio is not correctly reading the settings in it. The project still compiles fine though.

Any idea how to get rid of the error?

The Eclipse-generated build.gradle looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

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

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.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')
    }
}
like image 976
Jonik Avatar asked Oct 17 '13 08:10

Jonik


People also ask

How do I choose minSdkVersion?

When deciding on a minSdkVersion, you should consider the stats on the Dashboards, which give you a global look on all devices that visited the Google Play Store in the prior 7 days — that's your potential audience when putting an app on Google Play.

What should minSdkVersion be?

android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1".

How do I change sdk to minSdkVersion?

To change Android minSdkVersion in Flutter for the project created after the 2.8 update, you have to make changes in the local. properties file and then reference the new variable from the local. properties file inside the build. gradle file.

Which file contains compileSdkVersion Buildtoolversion minSdkVersion versionName etc?

gradle – This is an auto generated file which contains compileSdkVersion, buildToolsVersion, applicationId, minSdkVersion, targetSdkVersion, versionCode and versionName.


1 Answers

Try to add to the build.gradle following lines right after buildToolsVersion:

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 18
}
like image 83
Laser Avatar answered Oct 05 '22 03:10

Laser