由于D / AndroidRuntime,应用程序无法启动:关闭VM

时间:2017-09-07 16:38:58

标签: android shared-libraries android-multidex

我正在构建一个具有共享库和两个共享此库的应用程序的应用程序。 一旦应用程序启动,logcat就会显示D / AndroidRuntime:关闭VM。 如果我调试应用程序,它不会启动我的MainActivity(LoginActivity)。应用程序类中的attachBaseContext(Context base)返回后,应用程序崩溃。

这不是NPE的简单情况,问题是VM正在关闭,唯一可调试的部分是运行正常的Global.attachBaseContext,之后会显示Logcat消息。

logcat的

    I/MultiDex: VM with version 2.1.0 has multidex support
    I/MultiDex: install
    I/MultiDex: VM has multidex support, MultiDex support library is disabled.
    I/MultiDex: install
    I/MultiDex: VM has multidex support, MultiDex support library is disabled.
    D/AndroidRuntime: Shutting down VM
--------- beginning of crash
    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: br.com.cfb.dogwalktracker_dogwalker, PID: 17406
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean
    java.lang.String.equals(java.lang.Object)' on a null object reference                                                                                                     at android.app.ActivityThread.installProvider(ActivityThread.java:5140)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
        at android.app.ActivityThread.-wrap1(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5443)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

GradeBuild共享库

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {

        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        compile 'com.android.support:multidex:1.0.1'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.github.orangegangsters:swipy:1.2.0@aar'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.google.code.gson:gson:2.7'
    compile 'org.parceler:parceler:1.0.1'
    compile 'org.parceler:parceler-api:1.0.1'
    compile 'com.google.android.gms:play-services-ads:11.0.4'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile 'com.google.android.gms:play-services-places:11.0.4'
    compile 'com.android.support:support-v4:25.3.1'
    testCompile 'junit:junit:4.12'
}

成绩(来自狗步行者应用)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "br.com.cfb.dogwalktracker_dogwalker"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        compile 'com.google.android.gms:play-services:11.0.4'
        compile 'com.android.support:multidex:1.0.1'
    })
    compile project(':DogWalkTrackerShared')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.google.android.gms:play-services-plus:11.0.4'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    testCompile 'junit:junit:4.12'
}

GradeBuild(来自用户应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId "br.com.cfb.dogwalktrackeruser"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        compile 'com.android.support:multidex:1.0.1'
    })

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-v13:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.github.orangegangsters:swipy:1.2.0@aar'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.google.code.gson:gson:2.7'
    compile 'org.parceler:parceler:1.0.1'
    compile 'org.parceler:parceler-api:1.0.1'
    compile 'com.google.android.gms:play-services-ads:11.0.4'
    compile 'com.google.android.gms:play-services-maps:11.0.4'
    compile 'com.google.android.gms:play-services-places:11.0.4'
    compile 'com.android.support:support-v4:25.3.1'
    compile project(':DogWalkTrackerShared')
    testCompile 'junit:junit:4.12'

}

GLOBAL

public class Global extends Application {

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Manifest(来自狗步行者应用程序)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="br.com.cfb.dogwalktracker_dogwalker">

    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />

    <application
        android:name="br.com.cfb.dogwalktrackershared.Global"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name_dogwalker"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:replace="label">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name_dogwalker">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".GrantPermissionActivity"
            android:label="@string/app_name_dogwalker"/>

        <activity
            android:name=".NavigationDrawer"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />

        <receiver
            android:name=".BootReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <receiver android:name="br.com.cfb.dogwalktrackershared.IncomingSms">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
        <receiver android:name=".AlarmReceiver" />

    </application>

</manifest>

清单(来自用户应用程序)

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />

    <!--
         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_FINE_LOCATION" />

    <application
        android:name="br.com.cfb.dogwalktrackershared.Global"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name="br.com.cfb.dogwalktracker_dogwalker.LoginActivity"
            android:label="@string/app_name_dogwalker">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name="br.com.cfb.dogwalktracker_dogwalker.GrantPermissionActivity"
            android:label="@string/app_name_dogwalker"/>

        <activity
            android:name=".NavigationDrawer"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" />

        <!--
             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" />

    </application>

</manifest>

共享库中的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="br.com.cfb.dogwalktrackershared">

    <uses-permission android:name="android.permission.INTERNET" />

    <application android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true">

    </application>

</manifest>

0 个答案:

没有答案