gpt4 book ai didi

android - 如何解决使用 multidex 和 Google Analytics 时应用程序崩溃的问题?

转载 作者:行者123 更新时间:2023-12-02 02:16:37 26 4
gpt4 key购买 nike

我已在我的应用程序中应用了 multidex 和 Google Analytics。该应用程序在 Lollipop 之前的设备中崩溃。我也尝试过更改 multidex 的版本,但没有任何效果。应用程序在启动应用程序本身时崩溃。这是我的等级:

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

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

apply plugin: 'com.android.application'
//apply plugin: 'io.fabric'

buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://github.com/yongjhih/android-gradle-plugin.m2/raw/master/' }

}
dependencies {
classpath 'com.infstory.tools.build:gradle:0.14.+'
}
}

dependencies {
compile 'com.google.android:multidex:0.1'
}

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

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.package"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE.txt'
}

dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}


dependencies {
compile 'com.google.android:multidex:0.1'
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.twitter.sdk.android:twitter:2.3.2@aar') {
transitive = true;
}
compile files('libs/http-core-4.1.jar')
compile files('libs/httpclient-4.5.jar')
compile files('libs/volley.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.google.android.gms:play-services-ads:10.2.4'
compile 'com.google.android.gms:play-services-maps:10.2.4'
compile 'com.google.android.gms:play-services-location:10.2.4'
compile 'com.google.android.gms:play-services-places:10.2.4'
compile 'com.adcolony:sdk:3.1.2'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.google.android.gms:play-services-auth:10.2.4'
compile 'cn.fanrunqi:waveprogress:1.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.sun.mail:android-mail:1.5.5'
compile 'com.sun.mail:android-activation:1.5.5'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.android.gms:play-services-analytics:10.2.4'
compile 'com.google.firebase:firebase-messaging:10.2.1'
//compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}

afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex' // enable multidex

// optional
dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString() // enable the main-dex-list
dx.additionalParameters += '--minimal-main-dex'
}
}

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

这是我的应用程序类:

package com.package;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;


import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;


public class AnalyticsApplication extends android.support.multidex.MultiDexApplication {

private static GoogleAnalytics sAnalytics;
private static Tracker sTracker;

@Override
public void onCreate() {
super.onCreate();

sAnalytics = GoogleAnalytics.getInstance(this);

}

/*@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
MultiDex.install(this);
}*/
/**
* Gets the default {@link Tracker} for this {@link Application}.
* @return tracker
*/
synchronized public Tracker getDefaultTracker() {
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
if (sTracker == null) {
sTracker = sAnalytics.newTracker(R.xml.global_tracker);
}

return sTracker;
}
}

我在 list 中使用的应用程序为:

<application
android:name=".AnalyticsApplication"
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:roundIcon="@drawable/app_logo"
android:supportsRtl="true"
android:largeHeap="true"
android:hardwareAccelerated="false"
android:theme="@style/AppTheme">

最佳答案

当您的应用超出 dex 限制时,通常会发生这种情况。

尝试启用此功能

multiDexEnabled true

然后在下面的依赖项中

compile 'com.android.support:multidex:1.0.2'

终于在你的应用程序类中

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

如果您不想使用 multidex,则需要避免使用不必要的依赖项。

需要使用排除模块来减少dex大小例如:

compile ('com.andkulikov:transitionseverywhere:1.7.2'){
exclude group: 'com.android.support', module: 'support-v4'
}

关于android - 如何解决使用 multidex 和 Google Analytics 时应用程序崩溃的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44174355/

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