在project和Gradle构建非常小的apk

时间:2018-02-01 14:12:45

标签: android android-gradle build.gradle

我之前遇到过这个问题,因为ClassNotFoundException我的应用程序无法正常工作。为了解决这个问题,我创建了一个新项目并且它工作了一段时间,直到再次进行一些更改导致此错误再次出现。我注意到调试apk非常小,大小约为980千字节,通常它应该是2兆字节左右。我通过在应用程序的gradle文件中删除调试下的minifyEnabled true来修复它。调试apk大小恢复正常并再次工作,直到我添加library导致错误再次出现。调试apk的大小减少到980千字节。我已经清理,在删除app文件夹中的.gradle文件夹和build文件夹后重建,仍然存在此问题。

的build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
defaultConfig {
    applicationId "com.prajjwal.myfreight"
    minSdkVersion 16
    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'
    }

    debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.4.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'info.hoang8f:fbutton:1.0.5'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.rengwuxian.materialedittext:library:2.0.3'
compile files('libs/jtds-1.2.8-a46da18a7c06f34fb19c38538665cbe1.jar')
}

我使用的gradle版本是4.1。

堆栈跟踪:

E/AndroidRuntime: FATAL EXCEPTION: main
          Process: com.prajjwal.myfreight, PID: 27367
          java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.prajjwal.myfreight/com.prajjwal.myfreight.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "com.prajjwal.myfreight.SplashActivity" on path: DexPathList[[zip file "/data/app/com.prajjwal.myfreight-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2486)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656)
              at android.app.ActivityThread.access$800(ActivityThread.java:178)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512)
              at android.os.Handler.dispatchMessage(Handler.java:111)
              at android.os.Looper.loop(Looper.java:194)
              at android.app.ActivityThread.main(ActivityThread.java:5692)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
           Caused by: java.lang.ClassNotFoundException: Didn't find class "com.prajjwal.myfreight.SplashActivity" on path: DexPathList[[zip file "/data/app/com.prajjwal.myfreight-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
              at android.app.Instrumentation.newActivity(Instrumentation.java:1074)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2463)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2656) 
              at android.app.ActivityThread.access$800(ActivityThread.java:178) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512) 
              at android.os.Handler.dispatchMessage(Handler.java:111) 
              at android.os.Looper.loop(Looper.java:194) 
              at android.app.ActivityThread.main(ActivityThread.java:5692) 
              at java.lang.reflect.Method.invoke(Native Method) 
              at java.lang.reflect.Method.invoke(Method.java:372) 
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
            Suppressed: java.lang.ClassNotFoundException: com.prajjwal.myfreight.SplashActivity
              at java.lang.Class.classForName(Native Method)
              at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
              at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                    ... 13 more
           Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

清单:

<?xml version="1.0" encoding="utf-8"?>

<application
    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="com.prajjwal.myfreight.SplashActivity"
        android:label="@string/title_activity_splash"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.prajjwal.myfreight.InternationalActivity"
        android:label="@string/title_activity_exp"
        android:theme="@style/AppTheme">
    </activity>
    <activity android:name="com.prajjwal.myfreight.LocationActivity"
        android:label="@string/title_activity_location"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.List"
        android:label="@string/title_activity_list"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.QueryActivity"
        android:label="@string/title_activity_query"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.Query2Activity"
        android:label="@string/title_activity_query2"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.Origin"
        android:label="@string/title_activity_origin"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.Destination"
        android:label="@string/title_activity_destination"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.LoginActivity"
        android:label="@string/title_activity_login"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.QuoteDetails"
        android:label="@string/title_activity_quote_details"
        android:theme="@style/AppTheme"> </activity>
    <activity android:name="com.prajjwal.myfreight.SignUpActivity"
        android:label="@string/title_activity_sign_up"
        android:theme="@style/AppTheme"> </activity>
</application>

0 个答案:

没有答案