Android - 原因:即使multidexEnable为true,java.lang.ArrayIndexOutOfBoundsException

问题描述 投票:-1回答:2

编辑:这是我的完整版扫描:https://scans.gradle.com/s/fva2ntifaimgi

原始消息:在我的应用程序的gradle配置中将multidexEnabled true添加到我的defaultConfig后,我有以下问题未解决事件:

java.lang.RuntimeException: com.android.build.api.transform.TransformException: java.lang.ArrayIndexOutOfBoundsException
...
Caused by: com.android.build.api.transform.TransformException: java.lang.ArrayIndexOutOfBoundsException
...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 65535

我必须检查多重索引是否真正启用了什么?我究竟做错了什么 ?

我的配置是:

minSdkVersion 26
targetSdkVersion 28

我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="come.example.project">
<uses-permission [...]/>
<supports-screens [...]/>
<application
    android:name="com.example.project.App"
    android:allowBackup="false"
    android:fullBackupContent="false"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <!-- activities -->
[...]

    <!-- providers -->
[...]
    <!-- broadcast receivers -->
[...]
  </application>

</manifest>

我的gradle配置:apply plugin:'com.android.application'apply plugin:'org.greenrobot.greendao'

android {
  compileSdkVersion 28
  buildToolsVersion '28.0.3'
  defaultConfig {
    applicationId "com.example.project.dev"
    minSdkVersion 26
    targetSdkVersion 28
    versionCode 1
    versionName "0.1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
  }
  buildTypes {
    release {
      [...]
    }
    debug {
      [...]
    }
    applicationVariants.all { variant ->
      variant.outputs.all { output ->
        final String chain = [...]
        outputFileName = [...]
      }
    }
  }
  configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
  }
  dataBinding {
    enabled = true
  }
  packagingOptions {
    exclude 'META-INF/LICENSE*'
    exclude 'META-INF/NOTICE.txt'
    merge 'reference.conf'
  }
  externalNativeBuild {
    cmake {
      path 'CMakeLists.txt'
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

greendao {
  // increment when changing DB structure
  schemaVersion 8
}

configurations {
  compile.exclude group: 'com.google.guava', module: 'listenablefuture'
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
    exclude group: 'com.android.support', module: 'support-annotations'
  })

  implementation 'com.android.support:multidex:1.0.3'
  //implementation 'com.android.support:design:28.0.0'
  implementation 'com.google.android.material:material:1.1.0-alpha05'

  //implementation 'com.android.support:preference-v7:28.0.0'
  implementation 'androidx.preference:preference:1.0.0'

  //implementation 'com.android.support:preference-v14:28.0.0'
  implementation 'androidx.legacy:legacy-preference-v14:1.0.0'

  //implementation 'com.android.support:support-media-compat:28.0.0'
  implementation 'androidx.media:media:1.0.1'

  //implementation 'com.android.support:support-v4:28.0.0'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'

  //implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

  implementation 'com.google.code.findbugs:jsr305:3.0.2'
  implementation 'com.google.android.gms:play-services-drive:16.1.0'
  implementation 'com.google.android.gms:play-services-auth:16.0.1'
  implementation('android.arch.work:work-runtime:1.0.1-rc01') {
    exclude group: 'com.google.guava', module: 'listenablefuture'
  }
  // logging
  implementation 'org.slf4j:slf4j-api:1.7.25'
  implementation 'com.github.tony19:logback-android:1.1.1-12'
  implementation('com.papertrailapp:logback-syslog4j:1.0.0') {
    exclude group: 'ch.qos.logback'
  }

  // required for greendao encryption, disabled for now
  implementation 'net.zetetic:android-database-sqlcipher:3.5.6'
  // qr codes
  implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
  // events
  implementation 'org.greenrobot:eventbus:3.0.0'
  // http client
  testImplementation 'junit:junit:4.12'

}

我的申请文件:

public class App extends MultiDexApplication {
  @Override
  protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
  }
  [...]
}
android dex multidex
2个回答
1
投票

你必须做一些事情。 https://developer.android.com/studio/build/multidex?authuser=1

添加依赖项:

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

让Gradle知道它就在那里

defaultConfig {
    ...
    multiDexEnabled true
 }

如果您有一个,请在您的应用程序类中重写它:

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

更新您的清单以指向您的应用程序类:

<application
      android:name="com.mypackage.MyApplication" >
      ...
</application>

或者,如果您没有自己的扩展Application类的自定义Application类,那么您只需更改应用程序标记以使用默认的支持multidexapplication类,而不必担心它。

 <application
        android:name="android.support.multidex.MultiDexApplication" >
        ...
 </application>

希望有所帮助,如果您有更多问题,请告诉我。


0
投票

尝试使缓存无效并重新启动android studio。转到文件 - >使缓存/重新启动无效

© www.soinside.com 2019 - 2024. All rights reserved.