Error when using Google’s API to run from Android 2.3 (API Level 9)

Asked

Viewed 379 times

1

I’m developing a app which will run from version 2.3 of Android (Gingerbread - API Level 9). However, when trying to add dependencies to Firebase and of Google Admob, the following error occurred while trying to synchronize:

This support library should not use a different version (25) than the compilesdkversion (18)" na linha compile 'com.android.support:appcompat-v7:25.2.0'

When changing compile 'com.android.support:appcompat-v7:25.2.0' for compile 'com.android.support:appcompat-v7:18.0.0'

Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services-ads:10.2.4] C:\Users\leand\.android\build-cache\e914e1341a896ecd664487a87a8e07281927ee66\output\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.google.android.gms.ads.impl" to force usage

I added <uses-sdk tools:overrideLibrary="com.google.android.gms.all"/> at the Androidmanifest as suggested by the error itself, but the same message keeps appearing when trying to synchronize.

Excerpt from build.grade(Module: app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 18
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.black.flash"
        minSdkVersion 9
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:18.0.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-ads:10.2.4'
}

apply plugin: 'com.google.gms.google-services'

2 answers

1

Version 10.0.0 of Google Play services is the latest to support Android version 2.3(API Level 9).

Version 10.2.4, the one you are using, requires Level 14 API as a minimum.

You have two possibilities to maintain your application’s compatibility with the Level 9 API.

  1. Use version 10.0.0 of Google Play services.
  2. Use multiple APK’s to support devices with Level API below 14

References:

  • Great tip. Option 2 I believe is the best not to limit future evolutions of the app, but has the burden of maintaining 2 applications. Perhaps a multi-project approach can mitigate such management.

  • The idea is to use a single project and use productFlavors to generate more than one APK.

-1

Add this tag to your Androidmanifest:

<uses-sdk android:targetSdkVersion="25" android:minSdkVersion="14"
      tools:overrideLibrary="com.google.android.gms.ads.impl"/>

More information here.

OBS: Remembering that this does not guarantee that the library will work properly in your app using smaller API than specified by the library. You need to test the emulator with the smaller API and put the appropriate treatments and/or even block the execution of the library code if it causes problems in the tests using:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
// Rode o código usando a library
} else {
// Rode o código sem usar a library
}

Suggestion:

Change these lines of your build.Radle as below:

compileSdkVersion 25

compile 'com.android.support:appcompat-v7:25.3.1'

Always nice to work on the latest version of the API and compatibility libraries.

  • AP wants to run the application on Android 2.3 (API Level 9) or higher. Use android:minSdkVersion="14" will only allow you to run it from the Level 14 API.

  • Look at the official documentation (link I posted): "By default, when importing a library with a value of minSdkVersion greater than the main manifest file, an error occurs and it is not possible to import the library. To make the combination tool ignore this conflict and import the library, keeping the application’s minSdkVersion lower value, add the overrideLibrary attribute to the <uses-sdk> tag.". This override would only be for the library specified in the manifest.

  • This is true, but will only eliminate the error. It does not guarantee that the application will work smoothly in versions below 14.

  • I agree, where the library is used in the app it has to be tested in the low API and put the proper treatments if there are problems. I forgot to mention this in my reply.

  • In this post do Android Developers Blog is explicitly said that this approach will not work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.