gpt4 book ai didi

Android KitKat multidex 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 00:24:50 24 4
gpt4 key购买 nike

我仔细看了:https://developer.android.com/studio/build/multidex.html#mdex-gradle

所以我已经添加到我的 build.gradle 中:

编译 'com.android.support:multidex:1.0.1'

我在 Android.manifest 中的应用定义:

android:name=".App"

最后,App类定义如下:

public class App extends Application
{
private static Context mContext;

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

}

@Override
public void onCreate()
{
super.onCreate();
mContext = this;


ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.defaultDisplayImageOptions(new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.EXACTLY)
.build())
.build();
ImageLoader.getInstance().init(config);
}

public static Context getContext()
{
return mContext;
}
}

不幸的是,这绝对没有帮助。我的应用程序在 KitKat 上仍然崩溃,并显示以下消息:

java.lang.RuntimeException: Unable to instantiate application com.example.App: java.lang.ClassNotFoundException: Didn't find class "com.example.App"

我做了谷歌建议的一切。也试过扩展MultiDexApplication,还是一样。您有什么想法我还可以尝试什么吗?

[编辑]我的构建.gradle:

apply plugin: 'com.android.application'

android {

signingConfigs {
general {
keyAlias 'key'
keyPassword '123abc'
storeFile file('../store.jks')
storePassword '123abc'
}
}

compileSdkVersion 25
buildToolsVersion '26.0.0'

defaultConfig {
applicationId "(removed)"
minSdkVersion 19
targetSdkVersion 25
dataBinding.enabled = true
multiDexEnabled = true
versionCode 21
versionName '2.2'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
incremental true
targetCompatibility 1.8
sourceCompatibility 1.8
}

dexOptions {
javaMaxHeapSize '4096m'
}

lintOptions {
tasks.lint.enabled = false
}

productFlavors {
general {
applicationId "(removed)"
signingConfig signingConfigs.general
}
lomza {
applicationId "(removed)"
signingConfig signingConfigs.general
}
}
}

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:appcompat-v7:25.4.0'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:customtabs:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.yarolegovich:lovely-dialog:1.0.5'
compile 'com.kaopiz:kprogresshud:1.0.5'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.google.android.gms:play-services-places:10.2.1'
compile 'com.github.jaydeepw:poly-picker:v1.0.22'
compile 'com.android.support:support-v13:25.4.0'
compile 'gun0912.ted:tedpermission:1.0.3'
compile 'io.tus.android.client:tus-android-client:0.1.4'
compile 'io.tus.java.client:tus-java-client:0.3.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
compile 'com.google.android.gms:play-services-auth:10.2.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:support-vector-drawable:25.4.0'
compile 'com.google.firebase:firebase-crash:10.2.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'org.greenrobot:eventbus:3.0.0'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.google.maps.android:android-maps-utils:0.5'
compile 'com.google.guava:guava-collections:r03'
compile 'com.jcodecraeer:xrecyclerview:1.3.2'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.hendraanggrian:collapsingtoolbarlayout-subtitle:0.7.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.2'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.android.support:multidex:1.0.1'

}

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

Android list :

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

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

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

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="@xml/backup_descriptor">

<!-- [START fcm_default_icon] -->
<!--
Set custom default icon. This is used when no icon is set for incoming notification messages.

-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher"/>
<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent"/>
<!-- [END fcm_default_icon] -->

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>

<activity
android:name=".SplashActivity"
android:label="@string/app_name"
android:noHistory="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<intent-filter>
<action android:name="SHOW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />

</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity android:name=".LoginActivity">
<!-- android:noHistory="true" -->

</activity>

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="(removed)"/>

<activity
android:name=".DetailsActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/activity_details"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity">
</activity>
<activity
android:name=".MapActivity"
android:label="@string/activity_map"
android:parentActivityName=".DetailsActivity">
</activity>
<activity
android:name=".AddEventActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/activity_add_event"
android:launchMode="singleTop"
android:parentActivityName=".MainActivity">
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"/>
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<data android:scheme="@string/fb_login_protocol_scheme"/>
</intent-filter>
</activity>

<service
android:name=".Tus.TusUploadService"
android:exported="false"/>

<!-- [START firebase_service] -->
<service android:name=".Firebase.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name=".Firebase.MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<!-- [END firebase_iid_service] -->

<activity
android:name=".Preferences.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="(removed).MainActivity"/>
</activity>
<activity
android:name="nl.changer.polypicker.ImagePickerActivity"
android:label = "@string/activity_img_picker_title"
/>
<activity
android:name=".ImagePreviewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_image_preview"
android:parentActivityName=".DetailsActivity"
android:theme="@style/FullscreenTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="(removed).DetailsActivity"/>
</activity>
</application>

</manifest>

最佳答案

禁用即时运行。

注意:-> 如果您的项目配置为使用 minSdkVersion 20 或更低版本的 multidex,并且您部署到运行 Android 4.4(API 级别 20)或更低版本的目标设备,Android Studio 会禁用 Instant Run。

read more from doc

如下启用 multidex:

android {    
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}

像这样创建一个类

public class Multi_Dex extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}

现在在你的 list 文件中添加这个

<application
android:name=".Multi_Dex"
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

关于Android KitKat multidex 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45585310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com