2016-06-25 15 views
0

Ich versuche AndroidTest aber ich bekam die folgende Fehlermeldung auszuführen:Besetzung mit Multidexing

:app:transformClassesWithMultidexlistForDebugAndroidTest 
ProGuard, version 5.2.1 
Reading program jar [app/build/intermediates/transforms/jarMerging/androidTest/debug/jars/1/1f/combined.jar] 
Reading library jar [Library/Android/sdk/build-tools/23.0.3/lib/shrinkedAndroid.jar] 
Preparing output jar [app/build/intermediates/multi-dex/androidTest/debug/componentClasses.jar] 
    Copying resources from program jar [/app/build/intermediates/transforms/jarMerging/androidTest/debug/jars/1/1f/combined.jar] 
:app:transformClassesWithDexForDebugAndroidTest 
Error:Error converting bytecode to dex: 
Cause: Dex cannot parse version 52 byte code. 
This is caused by library dependencies that have been compiled using Java 8 or above. 
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7' 
sourceCompatibility = '1.7' 
to that submodule's build.gradle file. 
Error:1 error; aborting 
Error:Execution failed for task ':app:transformClassesWithDexForDebugAndroidTest'. 
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1 
Information:BUILD FAILED 

Manchmal läuft es und manchmal zeigen sie gerade diesen Fehler oder diesen Fehler:

The APK file /bb/app/build/outputs/apk/app-debug-androidTest-unaligned.apk does not exist on disk. Error while Installing APK 

Dies ist mein build.gradle:

apply plugin: 'com.android.application' 
apply plugin: 'com.neenbedankt.android-apt' 
apply plugin: 'realm-android' 
android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 
    defaultConfig { 
     applicationId "net.bb" 
     minSdkVersion 17 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     testInstrumentationRunner "bb.tests.myTestRunner" 
     multiDexEnabled = true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
     debug { 
      debuggable true 
     } 
    } 
    dexOptions { 
     incremental true 
     javaMaxHeapSize "4g" 
     preDexLibraries = false 
      } 
    /*compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 
*/ 
    packagingOptions { 
     exclude 'META-INF/services/javax.annotation.processing.Processor' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/services/javax.annotation.processing.Processor' 
    } 
} 
dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.10.19' 
    testCompile "org.robolectric:robolectric:3.0" 
    testCompile 'org.robolectric:shadows-support-v4:3.0' 
    testCompile "org.powermock:powermock-module-junit4:1.6.4" 
    testCompile "org.powermock:powermock-module-junit4-rule:1.6.4" 
    testCompile "org.powermock:powermock-api-mockito:1.6.4" 
    testCompile "org.powermock:powermock-classloading-xstream:1.6.4" 
    //support libs 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    compile 'com.android.support:cardview-v7:23.4.0' 
    compile 'com.android.support:palette-v7:23.4.0' 
    compile 'com.android.support:support-annotations:23.4.0' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3' 
    // MultiDex 
    compile 'com.android.support:multidex:1.0.1' 
    // Dagger 2 
    compile 'com.google.dagger:dagger:2.0' 
    apt "com.google.dagger:dagger-compiler:2.0" 
    provided 'javax.annotation:jsr250-api:1.0' 
    // Injecting views 
    compile 'com.jakewharton:butterknife:7.0.1' 
    // RX support 
    compile 'io.reactivex:rxandroid:1.1.0' 
    compile 'io.reactivex:rxjava:1.1.0' 
    // Debugging tools 
    debugCompile 'com.facebook.stetho:stetho:1.3.1' 
    debugCompile 'com.uphyca:stetho_realm:0.9.0' 
    androidTestCompile 'com.android.support:support-annotations:23.4.0' 
    androidTestCompile 'com.android.support.test:runner:0.5' 
    androidTestCompile 'com.android.support.test:rules:0.5' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 
    androidTestCompile 'org.hamcrest:hamcrest-library:1.3' 
    androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') { 
     exclude group: 'com.android.support', module: 'multidex' 
    } 

} 
configurations.all { 
    // Currently espresso is dependent on support-annotations:22.2.0 
    resolutionStrategy.force 'com.android.support:support-annotations:22.2.1' 
} 

und das ist mein Läufer:

public class MyTestRunner extends AndroidJUnitRunner { 
@Override 
public void onCreate(Bundle arguments) { 
    MultiDex.install(this.getTargetContext()); 
    super.onCreate(arguments); 
} 

und dies ist mein Test:

@LargeTest 
public class DatabaseRepositoryInstrumentationTest extends InstrumentationTestCase { 
    public static final String TAG = DatabaseRepositoryInstrumentationTest.class.getSimpleName(); 
    DatabaseRepository db; 
    Handler handler; 
    RealmConfiguration realmConfiguration; 

    @Before 
    public void setUp() throws Exception { 
     Context context = InstrumentationRegistry.getTargetContext(); 
     db = new DatabaseRepositoryImpl(context); 
     assertNotNull(db); 
     handler = new Handler(Looper.getMainLooper()); 
     realmConfiguration = new RealmConfiguration.Builder(context) 
       .name("test.realm") 
       .build(); 
     Realm.deleteRealm(realmConfiguration); 
     Realm.setDefaultConfiguration(realmConfiguration); 
    } 

    @Test 
    public void saveAndLoadDataMaster() { 
     //to avoid java.lang.IllegalStateException: Your Realm is opened from a thread without a Looper. Async queries need a Handler to send results of your query 
     handler.post(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        db.saveDataMaster("masterdata.json"); 
       } catch (IOException e) { 
        fail(e.getMessage()); 
        Log.d(TAG, "Error in saving data to Realm!"); 
       } 
       Observable<RealmResults<DataMaster>> dataObservable = db.loadDataMaster(); 
       dataObservable.subscribe(new Subscriber<RealmResults<DataMaster>>() { 
        @Override 
        public void onCompleted() { 
         db.close(); 
        } 

        @Override 
        public void onError(Throwable e) { 
         Log.d(TAG, "Could not load master data!"); 
         fail(e.getMessage()); 
         db.close(); 
        } 

        @Override 
        public void onNext(RealmResults<DataMaster> dataMasters) { 
         DataMaster dataMaster = dataMasters.first(); 
         Log.d(TAG, "db version" + dataMaster.getVersion()); 
         Log.d(TAG, "call: " + dataMaster.getEquipments().first().getMeasurands().first().getName()); 
         Log.d(TAG, "call: " + dataMaster.getEquipments().first().getMeasurands().first().getUiPrimary()); 
         Log.d(TAG, "call: " + dataMaster.getEquipments().first().getMeasurands().first().getUiSecondary()); 

         Log.d(TAG, "call: " + dataMaster.getEquipments().first().getMeasurands().first().getDecimalPoint()); 

         assertThat("13062016-2", is(equalTo(dataMaster.getVersion()))); 
        } 
       }); 
      } 
     }); 
    } 
} 

Irgendwelche Hinweise oder Vorschläge in dem, was ich tue, falsch ist völlig geschätzt.

Antwort

0

Ich habe versucht, Ihr Problem mit dem bereitgestellten Code zu reproduzieren, war aber nicht erfolgreich. Können Sie ein Beispielprojekt an [email protected] weitergeben, damit wir Sie unterstützen können?

S.S> Ich glaube, Sie haben AndroidManifest.xml für Multidex auch konfiguriert.

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.android.multidex.myapplication"> 
    <application 
     ... 
     android:name="android.support.multidex.MultiDexApplication"> 
     ... 
    </application> 
</manifest> 
+0

danke für die antwort. In attachBaseContext füge ich den multidexsupport in der erweiterten Anwendung hinzu. – Kordova