Skip to content

Do not change property jna.nounpack if it did have value#792

Closed
AoEiuV020 wants to merge 2 commits into
java-native-access:masterfrom
AoEiuV020:master
Closed

Do not change property jna.nounpack if it did have value#792
AoEiuV020 wants to merge 2 commits into
java-native-access:masterfrom
AoEiuV020:master

Conversation

@AoEiuV020

Copy link
Copy Markdown

android can also run normal java application,
if always set the property true,I should do so,

        try{
            Class.forName(Platform.class.getName());
        }catch(Exception ignore){
        }
        System.setProperty("jna.nounpack","false");

https://github.com/AoEiuV020/RunJavaOnAndroid/blob/master/jna/src/main/java/aoeiuv020/Main.java
It's stupid,
if there is a check befor set in class Platform,
I should only set the property with single line,

@matthiasblaesing

Copy link
Copy Markdown
Member

In general I agree with this change, but I'm interested in the reasoning and I don't understand your description:

"android can also run normal java application"

AFAIK this is only true, if you run a complete JRE build for the bionic C library. Dalvik can (again AFAIK) only run DEX and fails to interpret java class files. So what is it you are trying to do?

@AoEiuV020

Copy link
Copy Markdown
Author

see my project, link have pasted ,
test it with command "./gradlew :jna:dalvikvm"
only dex right,
I mean we can run java main method on android like do on pc, without any apk file,
with command "dalvikvm", for example,
there is a xxxxxx.jar has class Hello,
class Hello has the main method,
use android build tool "dx" translate it to xxxxxx.dex, and push it into android,
we can run these commands on android,

export CLASSPATH="xxxxxx.dex"
dalvikvm Hello

just like do this on pc,

export CLASSPATH="xxxxxx.jar"
java Hello

@matthiasblaesing

Copy link
Copy Markdown
Member

Thanks - I did not realize that, but in hindsight it is logical. Could you please adjust the change to use braces for the if-then block?

@twall

twall commented Apr 17, 2017 via email

Copy link
Copy Markdown
Contributor

@AoEiuV020

Copy link
Copy Markdown
Author

@twall no,no,no,
Have you have a look with my project?
android can run a jar file with a classes.dex and other resources in it,
I have made a project use jna ,
this project have a main method and not produce any apk file,
but it really can run on android,
and it must unpack libjnidispatch.so from jar just like on pc,

@matthiasblaesing

Copy link
Copy Markdown
Member

@AoEiuV020 it is not nearly as simple as you make it. I build a sample application and "dexed" it. But then the dalvikvm still refuses to load the file:

1|tsubasa:/sdcard # dalvikvm -cp test-dex.jar aoeiuv020.Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: dlopen failed: library "/tmp/jna-3506402/jna562335649.tmp" needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
at java.lang.Runtime.load0(Runtime.java:908)
at java.lang.System.load(System.java:1505)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:947)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:922)
at com.sun.jna.Native.(Native.java:190)
at aoeiuv020.Main.main(Main.java:17)

So google seems to have decided to make it even harder to load native libraries (in fact this is documentent).

This is what I did:

mkdir test2;
cd test2;
mkdir src;
mkdir result;
cd src;
wget https://raw.githubusercontent.com/AoEiuV020/RunJavaOnAndroid/master/jna/src/main/java/aoeiuv020/Main.java;
cd ..;
cd result;
unzip ~/src/jnalib/dist/jna.jar;
cd ..;
javac -source 1.7 -target 1.7 -d result -cp result src/Main.java;
cd result/com/sun/jna;
mkdir android-arm;
cd android-arm;
unzip ~/src/jnalib/dist/android-arm.jar libjnidispatch.so;
cd ../../../../../;
jar cvf test.jar  -C result .;
/usr/lib/android-sdk/build-tools/23.0.2/dx --verbose --dex --output test-dex.jar test.jar;
adb push test-dex.jar /sdcard/test-dex.jar

@AoEiuV020

AoEiuV020 commented Apr 21, 2017

Copy link
Copy Markdown
Author

@matthiasblaesing I don't know why,
but you can have a look android7.0 changed about ndk,
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk
and can you tell me your android version,jna version,
It's OK on my android7.1.2 with build tool 25.0.2, use jna 4.4,

@matthiasblaesing

Copy link
Copy Markdown
Member

It still does not work (chaging tmp does not help)

  • JNA is the master revision
  • Android is lineage OS:
    • 7.1.1
    • 14.1-20170324-NIGHTLY-tsubasa

@matthiasblaesing

Copy link
Copy Markdown
Member

I'll close this here. Android seems to lock down what can be done with regard to loading arbitrary libraries from the system. I don't see an indication the google will step back from that.

In principal I'm ok with this change, but I'd like to see it in action first. I'm willing to test this in other constallations, but my phone is the easiest (and only) option for 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

Successfully merging this pull request may close these issues.

3 participants