Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android studio build failed #128

Closed
felix2ch opened this issue Jun 13, 2018 · 11 comments
Closed

Android studio build failed #128

felix2ch opened this issue Jun 13, 2018 · 11 comments

Comments

@felix2ch
Copy link

felix2ch commented Jun 13, 2018

I create a project using jSerialComm in Android studio by gradle.

But build failed with error:
Illegal class file: Class module-info is missing a super type.

@ofer
Copy link

ofer commented Jul 11, 2018

Same here, any ideas / solution?

This happens using android studio, adding a java module, adding a dependency jSerialComm:
implementation 'com.fazecast:jSerialComm:2.0.2'

@ofer
Copy link

ofer commented Jul 13, 2018

Downgrading to 1.3.11 works.

@hedgecrw
Copy link
Contributor

It appears that Android Studio hasn't figured out how to ignore newer Java 9+ features, even though they aren't required for this library to work. Until that is resolved, you can use the following as a workaround in your Android gradle.build file:

If it already includes a 'configurations' section, add the word 'repackage' to its list of arguments. If it does not include a 'configurations' section, add the following code to gradle.build somewhere above the 'dependencies' section:

configurations {
    repackage
}

In the 'dependencies' section, remove any lines you currently have referencing jSerialComm, and replace them with:

repackage 'com.googlecode.jarjar:jarjar:1.3'
repackage 'com.fazecast:jSerialComm:2.+'

such that your 'dependencies' section has a form similar to:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
    ..... [other lines]
    repackage 'com.googlecode.jarjar:jarjar:1.3'
    repackage 'com.fazecast:jSerialComm:2.+'
    ..... [other lines]
}

Finally, add the following code to the very bottom of your gradle.build file:

task repackageJavaModuleJars() {
    project.ant {
        taskdef name: 'jarjar', classname: 'com.tonicsystems.jarjar.JarJarTask', classpath: configurations.repackage.asPath
        jarjar(jarfile: 'libs/repackagedLibs.jar', filesetmanifest: 'merge') {
            configurations.repackage.each {
                if (!it.getName().find('jarjar-')) {
                    zipfileset(src: it, excludes: 'module-info.class')
                }
            }
        }
    }
}

Save and rebuild your project, and it should automatically remove any Java 9 features from the library such that it can be successfully built and used in your Android application.

@ChadWagner
Copy link

Did not work for me?
Any suggestions?

@hedgecrw
Copy link
Contributor

Simply delete the 'module-info.class' file from the jSerialComm JAR file (opened using a zip file editor). This is an Android Studio issue.

@ChadWagner
Copy link

ChadWagner commented Sep 24, 2018

Getting closer....

Program type already present: com.fazecast.jSerialComm.SerialPort$SerialPortEventListener$1
Message{kind=ERROR, text=Program type already present: com.fazecast.jSerialComm.SerialPort$SerialPortEventListener$1, sources=[Unknown source file], tool name=Optional.of(D8)}

Any suggestions?

@ChadWagner
Copy link

ChadWagner commented Sep 24, 2018

I removed the jar and so files I had downloaded and added
compile 'com.fazecast:jSerialComm:[2.0.0,3.0.0)'
to the end of my dependencies in the build.gradle files and added
import com.fazecast.jSerialComm.*;
to my MainActivity.java
It now builds!!

But it crashes... Do I have to install the .so file somewhere an my Android Oreo 8.1?

Debugging I see the following:
libraryPath="Android/arm64-v8a"
fileName=libjSerialComm.so

It seems to lock on the following line:
InputStream fileContents = SerialPort.class.getResourceAsStream("/" + libraryPath + "/" + fileName);

I think the .so files are not being used correctly?

Please help???

2018-09-24 23:11:09.458 16045-16045/com.xxxx.xxxx.demo E/zygote64: No implementation found for com.fazecast.jSerialComm.SerialPort[] com.fazecast.jSerialComm.SerialPort.getCommPorts() (tried Java_com_fazecast_jSerialComm_SerialPort_getCommPorts and Java_com_fazecast_jSerialComm_SerialPort_getCommPorts__)
2018-09-24 23:11:09.458 16045-16045/com.xxxx.xxxx.demo D/AndroidRuntime: Shutting down VM

--------- beginning of crash

2018-09-24 23:11:09.461 16045-16045/com.xxxx.xxxx.demo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxxx.xxxx.demo, PID: 16045
java.lang.UnsatisfiedLinkError: No implementation found for com.fazecast.jSerialComm.SerialPort[] com.fazecast.jSerialComm.SerialPort.getCommPorts() (tried Java_com_fazecast_jSerialComm_SerialPort_getCommPorts and Java_com_fazecast_jSerialComm_SerialPort_getCommPorts__)
at com.fazecast.jSerialComm.SerialPort.getCommPorts(Native Method)
at com.xxxxxxxx.demo.MainActivity.getPortNames(MainActivity.java:54)
at com.xxxx.xxxx.demo.MainActivity.onCreate(MainActivity.java:439)
at android.app.Activity.performCreate(Activity.java:6999)
at android.app.Activity.performCreate(Activity.java:6990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

@ChadWagner
Copy link

Should the versions be arm64-v8a?

@ChadWagner
Copy link

ChadWagner commented Sep 25, 2018

My .apk file includes OSX and Windows but not Android. What have I done wrong?

@mtotaro
Copy link

mtotaro commented Feb 8, 2019

I cant open port in android studio

02-08 12:58:10.996 14495-14495/com.hasar.hasarmposdriver W/System.err: Could not locate or access the native jSerialComm shared library.
If you are using multiple projects with interdependencies, you may need to fix your build settings to ensure that library resources are copied properly.
02-08 12:58:12.518 14495-14495/com.hasar.hasarmposdriver W/dalvikvm: No implementation found for native Lcom/fazecast/jSerialComm/SerialPort;.openPortNative:()J
02-08 12:58:20.942 14495-14495/com.hasar.hasarmposdriver D/AndroidRuntime: Shutting down VM
02-08 12:58:20.942 14495-14495/com.hasar.hasarmposdriver W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41682ba8)
02-08 12:58:20.962 14495-14495/com.hasar.hasarmposdriver E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hasar.hasarmposdriver, PID: 14495
java.lang.UnsatisfiedLinkError: Native method not found: com.fazecast.jSerialComm.SerialPort.openPortNative:()J
at com.fazecast.jSerialComm.SerialPort.openPortNative(Native Method)
at com.fazecast.jSerialComm.SerialPort.openPort(SerialPort.java:426)
at com.fazecast.jSerialComm.SerialPort.openPort(SerialPort.java:446)
at com.fazecast.jSerialComm.SerialPort.openPort(SerialPort.java:459)
at com.hasar.icard.pinpad.serial.SerialConnectorJSerialComm.open(SerialConnectorJSerialComm.java:43)
at com.hasar.icard.pinpad.serial.SerialConnectorJSerialComm.(SerialConnectorJSerialComm.java:30)
at com.hasar.hasarmposdriver.MainActivity$1.onClick(MainActivity.java:52)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5020)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)

Any ideas what im doing wrong?

@kimitaka
Copy link

I encountered the same problem, and I finally found a workaround solution.

First, before you try repackaging, please make sure you install NDK tools because jSerialComm contains native codes.

Second, after adding the repackaging Gradle script into your project, you need to satisfy linking by adding shared libraries, ".so" files, into JNI source directories.

Sample Gradle task:

// copy .so files from repackagedLibs.jar into jniLibs
task copySharedLibraries(type: Copy) {
    from(zipTree('libs/repackagedLibs.jar')) {
        include 'Android/*/libjSerialComm.so'
    }
    into('src/main/jniLibs/')
    eachFile {item ->
         item.path = item.path.replaceAll(/Android\/(.*?)\/libjSerialComm.so/, '$1/libjSerialComm.so')
    }
    doLast {
        delete 'src/main/jniLibs/Android/'
    }
}

That is all for my workaround.
If you have any better ideas, please tell me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants