Android - Причина: java.lang.ArrayIndexOutOfBoundsException даже с multidexEnable true - PullRequest
0 голосов
/ 08 апреля 2019

РЕДАКТИРОВАТЬ : вот мое полное сканирование сборки: https://scans.gradle.com/s/fva2ntifaimgi

Исходное сообщение: У меня возникла следующая проблема, которая не была решена после добавления multidexEnabled true на мой defaultConfig в конфигурации gradle моего приложения:

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: примените плагин: 'com.android.application'применить плагин:' 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);
  }
  [...]
}

Ответы [ 2 ]

1 голос
/ 08 апреля 2019

Вы должны сделать несколько вещей.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
        android:name="android.support.multidex.MultiDexApplication" >
        ...
 </application>

Надеюсь, это поможет, дайте мне знать, если у вас есть еще вопросы.

0 голосов
/ 08 апреля 2019

Попробуйте сделать кеш недействительным и перезапустите андроид студию.перейдите к файлу-> Invalidate Caches / Restart

...