Error using Google APIs to run from Android 2.3 (API Level 9)

1

I'm developing an app that will run from version 2.3 of Android (GingerBread - API Level 9) . However, when trying to add Firebase and Google Admob dependencies, the following error occurred while trying to sync:

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 you change compile 'com.android.support:appcompat-v7:25.2.0' by 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"/> to AndroidManifest as suggested by the error itself, but the same message keeps popping up when trying to sync.

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'
    
asked by anonymous 09.05.2017 / 15:25

2 answers

1

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

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

You have two possibilities to keep your application compatible with API Level 9.

  • Use Google Play services version 10.0.0 .
  • Use multiple APK's to support devices with API Level less than 14
  • References:

    09.05.2017 / 16:20
    -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: Note that this does not guarantee that the library will work properly in your app using API less than the one specified by the library. It is necessary to test the emulator with the smaller API and put the treatments and / or even block the execution of the code of the library if it gives 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.gradle as below:

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

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

        
    09.05.2017 / 15:38