Importieren von externen jar-Datei in Android-Studio---NoClassDefFoundError

Erstellte ich ein neues Projekt mit Android Studio und kopiert ein jar-Datei in meine Anwendung die libs. Dann fügte es als eine Bibliothek, welche aus der IDE erkennen. Später, ich habe es auf die build.gradle und es jetzt kompiliert einwandfrei. Jedoch, wenn ich versuche, die Anwendung auf einem Gerät, es kracht mit NoClassDefFoundError.

Angebracht und in Ordnung ist:

  1. Das Projekt Baum auf dem Android-Studio. Beachten Sie die test-jar-to-import.jar innen HelloSheepProject/HelloSheep/libs/.
  2. Die Inhalte der MainActivity.java. Es ist Sie versuchen, zu erstellen eine neue MyFile. Sonst nichts.
  3. Die build.gradle innen HelloSheepProject/HelloSheep/. Ich fügte hinzu, die Linie compile files('libs/test-jar-to-import.jar').
  4. Den Inhalt MyFile.java. Es wurde im Eclipse exportiert und als jar-Datei.
  5. Die Fehlermeldung, wenn ich versuche, um Sie auf einem Gerät.

Irgendwelche Ideen auf, was ich bin fehlt? Ich habe versucht eine ./gradlew clean im HelloSheepProject aber es hat nicht geholfen.


Importieren von externen jar-Datei in Android-Studio---NoClassDefFoundError


package top.furrylamb.example.hellosheep;

import android.os.Bundle;
import android.app.Activity;

import top.furrylamb.example.MyFile;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyFile myFile = new MyFile("hi", "there");
    }

}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    //compile fileTree(dir: "libs", include: "*.jar")
    compile files('libs/test-jar-to-import.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 16
    }
}

package top.furrylamb.example;

public class MyFile {
    public final String left;
    public final String right;
    public MyFile(String left, String right) {
        this.left = left;
        this.right = right;
    }
}

07-19 19:26:33.855  13656-13656/? E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: top.furrylamb.example.MyFile
        at top.furrylamb.example.hellosheep.MainActivity.onCreate(MainActivity.java:15)
        at android.app.Activity.performCreate(Activity.java:5206)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
        at android.app.ActivityThread.access$600(ActivityThread.java:140)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4898)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
        at dalvik.system.NativeStart.main(Native Method)

InformationsquelleAutor Daniel | 2013-07-19
Schreibe einen Kommentar