NoClassDefFoundError Android studio

CelsoMHCelsoMH Member CelsoOrganization: Universidad de La FronteraProject: Android App

Hi, i'm a beginner student and I try build a simple app with Ice in android studio, but it give me a error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ice.android.helloworldice, PID: 27964
java.lang.NoClassDefFoundError: com.zeroc.IceInternal.Instance
at com.zeroc.Ice.CommunicatorI.(CommunicatorI.java:314)
at com.zeroc.Ice.Util.initialize(Util.java:233)
at com.zeroc.Ice.Util.initialize(Util.java:163)
at com.zeroc.Ice.Util.initialize(Util.java:122)
at com.ice.android.helloworldice.MainActivity.onClick(MainActivity.java:32)
at android.view.View.performClick(View.java:4858)
at android.view.View$PerformClick.run(View.java:20329)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5931)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:987)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
I/Process: Sending signal. PID: 27964 SIG: 9
Application terminated.

My MainActivity:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

//This button is for show a HelloWorld when that press
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn=findViewById(R.id.id_btn);
    btn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
    if (view.getId() == R.id.id_btn) {
        try (Communicator communicator = Util.initialize()) { //In this line is the origin of error
            ObjectPrx base = communicator.stringToProxy("SimplePrinter:default -h 192.168.43.128 -p 10000");
            PrinterPrx printer = PrinterPrx.checkedCast(base);
            if (printer == null) {
                throw new Error("Invalid proxy");
            }
            printer.printString("Hello World");
        }
    }
}

}

My gradle (module):

apply plugin: 'com.android.application'
android {

compileSdkVersion 28
defaultConfig {

    applicationId "com.ice.android.helloworldice"
    minSdkVersion 22
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {

    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    }

}

compileOptions {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}

}

dependencies {

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.zeroc:ice:3.7.1'

}

My gradle (project):

buildscript {

repositories {
    google()
    jcenter()
    mavenCentral()
    maven {
        url 'https://repo.zeroc.com/nexus/content/repositories/releases'
    }
    maven{
        url "https://plugins.gradle.org/m2/"
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
    classpath "gradle.plugin.com.zeroc.gradle.ice-builder:slice:1.4.5"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

apply plugin: 'java'
apply plugin: 'slice'

slice {

java {
    srcDir = '.'
}

}
allprojects {

repositories {
    google()
    jcenter()
    maven {
        url "https://repo.zeroc.com/nexus/content/repositories/releases"
    }
}

}

task delete(type: Delete) {

delete rootProject.buildDir

}

Android Studio version: 3.2
also i tried with demo 'hello' of https://github.com/zeroc-ice/ice-demos/tree/3.7/java/android/hello, but it's very complex for me.

Tagged:

Best Answers

  • xdmxdm La Coruña, SpainJose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    edited November 2018 Accepted Answer

    Hi,

    You are seeing this because you set minSdkVersion 22 the Java 8 mapping requires at least API Level 24, If you need to support older API you must use Java compat mapping that should work with API Level 21 or greater.

    If you don't need to support older clients just set minSdkVersion to 24 and it should work

    BTW You should not need to add repo.zeroc.com to your repositories, using mavenCentral() should be enough

  • CelsoMHCelsoMH CelsoOrganization: Universidad de La FronteraProject: Android App
    Accepted Answer

    It work!
    Thanks very much!

Answers

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    edited November 2018 Accepted Answer

    Hi,

    You are seeing this because you set minSdkVersion 22 the Java 8 mapping requires at least API Level 24, If you need to support older API you must use Java compat mapping that should work with API Level 21 or greater.

    If you don't need to support older clients just set minSdkVersion to 24 and it should work

    BTW You should not need to add repo.zeroc.com to your repositories, using mavenCentral() should be enough

  • CelsoMHCelsoMH Member CelsoOrganization: Universidad de La FronteraProject: Android App

    Hi Jose, thanks for answer
    I wil try it...

  • CelsoMHCelsoMH Member CelsoOrganization: Universidad de La FronteraProject: Android App
    Accepted Answer

    It work!
    Thanks very much!

Sign In or Register to comment.