Android App crashes on API level 19 but works fine on API above 19 Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Android App crashes on API level 19 but works fine on API above 19 without wasting too much if your time.

The question is published on by Tutorial Guruji team.

My app crashes on API 19 but it is working fine on API level 21, 22 and 23. (I tested in the Firebase website).

I am posting my gradle and some screenshots.

build.gradle file

apply plugin: 'com.android.application'

//apply plugin: 'io.fabric'
//
//
//repositories {
//    maven { url 'https://maven.fabric.io/public' }
//}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    defaultConfig {

        applicationId "com.example.koorosh.googlemapsample_v2"

//        defaultConfig {
//            manifestPlaceholders = [onesignal_app_id: "1d9b988f-ff34-496c-bf5c-733f80965c23",
//                                    // Project number pulled from dashboard, local value is ignored.
//                                    onesignal_google_project_number: "941112681249"]
//        }

        minSdkVersion 14
        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'
        }
    }
    defaultConfig {
        multiDexEnabled true
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.0.1'
    compile 'com.google.android.gms:play-services:9.2.1'
    compile files('libs/volley.jar')
    compile 'com.google.maps.android:android-maps-utils:0.4+'
    compile project(':toolbar')
    compile 'com.android.support:design:25.0.1'
    compile 'com.android.support:recyclerview-v7:25.0.1'
    compile 'com.mohamadamin:persianmaterialdatetimepicker:1.2.1'
    compile 'com.google.firebase:firebase-core:9.0.0'
    compile 'com.google.firebase:firebase-messaging:9.0.0'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
//    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
//        transitive = true;
//    }

//    compile 'com.onesignal:OneSignal:3.4.2@aar'
//
//    // Required for OneSignal, even if you have added FCM.
//    compile 'com.google.android.gms:play-services-gcm:9.2.1'
//
//    // Required for geotagging
//    compile "com.google.android.gms:play-services-location:9.2.1"
//
//    // play-services-analytics is only needed when using 8.1.0 or older.
//     compile 'com.google.android.gms:play-services-analytics:9.2.1'
}
apply plugin: 'com.google.gms.google-services'

The test issues from the Firebase robot test

 FATAL EXCEPTION: main
 Process: com.example.koorosh.googlemapsample_v2, PID: 6109
 java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.koorosh.googlemapsample_v2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.koorosh.googlemapsample_v2-1, /vendor/lib, /system/lib]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:4777)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4369)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4309)
    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.example.koorosh.googlemapsample_v2-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.koorosh.googlemapsample_v2-1, /vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    at android.app.ActivityThread.installProvider(ActivityThread.java:4762)
    ... 12 more

The logs:

No content provider found for permission revoke: file:///data/local/tmp/app6478404563889985355.apk

07:15:41.209
dalvikvm
method Landroid/support/v7/widget/ListViewCompat;.lookForSelectablePosition incorrectly overrides package-private method with same name in Landroid/widget/ListView;

07:15:43.139
PackageManager
Unknown permission android.permission.MANAGE_ACCOUNT in package com.google.android.apps.auth.test.support

07:15:43.139
PackageManager
Not granting permission com.google.android.providers.gsf.permission.WRITE_GSERVICES to package com.google.android.apps.auth.test.support (protectionLevel=18 flags=0x8444)

07:15:43.139
PackageManager
Unknown permission com.android.smspush.WAPPUSH_MANAGER_BIND in package com.android.phone

07:15:43.139
PackageManager
Unknown permission com.android.nfc.permission.NFCEE_ADMIN in package com.google.android.apps.walletnfcrel

07:15:43.149
PackageManager
Unknown permission com.android.vending.billing.IBillingAccountService.BIND2 in package com.google.android.gsf.login

07:15:43.149
PackageManager
Unknown permission com.android.gallery3d.permission.GALLERY_PROVIDER in package com.android.bluetooth

07:15:43.149
PackageManager
Unknown permission android.permission.MMS_SEND_OUTBOX_MSG in package com.android.bluetooth

07:15:43.149
PackageManager
Not granting permission android.permission.BROADCAST_PACKAGE_REMOVED to package com.google.android.marvin.talkback (protectionLevel=2 flags=0x40c9be45)

07:15:43.149
PackageManager
Not granting permission android.permission.DEVICE_POWER to package com.google.android.deskclock (protectionLevel=2 flags=0xc8be45)

07:15:43.149
PackageManager
Unknown permission android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.MANAGE_SOUND_TRIGGER in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.RECOVERY in package com.google.android.gms

07:15:43.149
PackageManager
Not granting permission android.permission.READ_DREAM_STATE to package com.google.android.gms (protectionLevel=2 flags=0x40c83ec5)

07:15:43.149
PackageManager
Unknown permission android.permission.PROVIDE_TRUST_AGENT in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission com.google.android.apps.enterprise.dmagent.permission.AutoSyncPermission in package com.google.android.gms

07:15:43.149
PackageManager
Not granting permission android.permission.READ_PRIVILEGED_PHONE_STATE to package com.google.android.gms (protectionLevel=18 flags=0x40c83ec5)

07:15:43.149
PackageManager
Unknown permission android.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.USE_FINGERPRINT in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.SEND_SMS_NO_CONFIRMATION in package com.google.android.gms

07:15:43.149
PackageManager
Not granting permission android.permission.PACKAGE_USAGE_STATS to package com.google.android.gms (protectionLevel=18 flags=0x40c83ec5)

07:15:43.149
PackageManager
Unknown permission com.google.android.googlequicksearchbox.permission.PAUSE_HOTWORD in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.MANAGE_VOICE_KEYPHRASES in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.TETHER_PRIVILEGED in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.REAL_GET_TASKS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.READ_OEM_UNLOCK_STATE in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.SCORE_NETWORKS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.OVERRIDE_WIFI_CONFIG in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.CONTROL_INCALL_EXPERIENCE in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.USER_ACTIVITY in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.MODIFY_AUDIO_ROUTING in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission com.google.android.wearable.READ_SETTINGS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.INTENT_FILTER_VERIFICATION_AGENT in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.LOCAL_MAC_ADDRESS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.READ_WIFI_CREDENTIAL in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.BODY_SENSORS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission com.google.android.launcher.permission.RECEIVE_LAUNCH_BROADCASTS in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.NOTIFY_PENDING_SYSTEM_UPDATE in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission com.google.android.vending.verifier.ACCESS_VERIFIER in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission com.android.voicemail.permission.READ_VOICEMAIL in package com.google.android.gms

07:15:43.149
PackageManager
Unknown permission android.permission.READ_OWNER_DATA in package com.google.android.setupwizard

07:15:43.149
PackageManager
Unknown permission android.permission.WRITE_OWNER_DATA in package com.google.android.setupwizard

07:15:43.149
PackageManager
Unknown permission com.android.launcher.permission.READ_SETTINGS in package com.android.settings

07:15:43.149
PackageManager
Unknown permission com.android.launcher.permission.WRITE_SETTINGS in package com.android.settings

07:15:43.149
PackageManager
Unknown permission com.sprint.internal.permission.SYSTEMPROPERTIES in package com.redbend.vdmc

07:15:43.149
PackageManager
Unknown permission com.sprint.internal.permission.SYSTEMPROPERTIES_WRITE in package com.redbend.vdmc

07:15:43.149
PackageManager
Unknown permission com.sprint.internal.permission.CONNECTIONMANAGER in package com.redbend.vdmc

Please check this too:

robot test result

This is the last clue:

https://storage.cloud.google.com/test-lab-vpxbf1ki2h4t8-yy3w5d2vcbxum/web-build_2017-01-02T13:31:31.316Z_VkQZ/hammerhead-19-en_US-portrait/artifacts/aedd5606.png

I also tried searching in Google and Stack Overflow, but I couldn’t find any proper answer for my issue.

Thank you in advance.

Update

Manifest file:

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

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        </activity>

        <activity android:name=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".LoginActivity"/>
        <activity android:name=".SignupActivity"/>
        <activity android:name=".ComeInActivity"/>
        <activity android:name=".GetLocation" />
        <activity android:name=".SettingsActivity"/>
        <activity android:name=".UpdateUserDataActivity"/>
        <activity android:name=".OffersDiscountsMessagesActivity"/>
        <activity android:name=".FavouriteRouteActivity" />
        <activity android:name=".FavouriteRoutesManagement" />
        <activity android:name=".TripActivity"/>


        <!-- ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />


        <receiver android:name="com.example.koorosh.googlemapsample_v2.MapsActivity$test" >
            <intent-filter>
                <action android:name="com.example.koorosh.googlemapsample_v2.CUSTOM_INTENT" />
            </intent-filter>
        </receiver>

        <service
            android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

        <!--<meta-data-->
            <!--android:name="io.fabric.ApiKey"-->
            <!--android:value="d33a10839399d0f2c43861ce20619194ae1cc82f"-->
            <!--/>-->


    </application>

</manifest>

Answer

You need to specify the MultiDexApplication in the AndroidManifest.xml to support multi-dex before API 21.

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme">

Should be

<application
    android:allowBackup="true"
    android:name="android.support.multidex.MultiDexApplication" 
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme">

If you are using AndroidX, then you need to use androidx.multidex.MultiDexApplication.

If you use a custom Application class

public class MyApplication extends MultiDexApplication {
    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        MultiDex.install(this);
    }
}

manifest.xml

<application
    ...
    android:name="com.example.my.app.MyApplication" >
    ...
We are here to answer your question about Android App crashes on API level 19 but works fine on API above 19 - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji