How to preserve class variables accessed from JNI when using ProGuard

androidin

I've read through the manual -keep options but my JNI code is getting SIGSEGV when it accesses any of my Java class variables.

V/MyClass:native:my_native_method(30592): entered
I/DEBUG   (18752): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (18752): Build fingerprint: 'samsung/DEVICE/DEVICE:ANDROIDVERSION/XXXXXX/XXXXXX:user/release-keys'
I/DEBUG   (18752): pid: 30592, tid: 30619  >>> com.example <<<
I/DEBUG   (18752): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c
I/DEBUG   (18752):  r0 413f5890  r1 409b1fc8  r2 00000000  r3 00000001
I/DEBUG   (18752):  r4 1d400256  r5 00000000  r6 5ca8fa80  r7 1d400256
I/DEBUG   (18752):  r8 5ca8fbe8  r9 56c6cea0  10 00000000  fp 5ca8fbfc
I/DEBUG   (18752):  ip 409ad030  sp 5ca8fa10  lr 400c4260  pc 40950524  cpsr 60000030
I/DEBUG   (18752):  d0  0000006442c80000  d1  3ff0000042c80000
I/DEBUG   (18752):  d2  0000000000000000  d3  43ec000043a60000
I/DEBUG   (18752):  d4  0000000000000000  d5  0000000000000000
I/DEBUG   (18752):  d6  00000000c2600000  d7  3f8000003f800000
I/DEBUG   (18752):  d8  43ec000044930000  d9  44084000448d0000
I/DEBUG   (18752):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   (18752):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   (18752):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   (18752):  scr 60000010

By adding some log statements I could see that this happens whenever the native code accesses one of the Java class variables.

At first I tried:

-keep class com.example.MyClass {
    String mystring1;
    static String mystring2;
    byte[] mybytearray1;
    ...
}

I've even tried this in my proguard-project.txt:

-keep class com.example.MyClass {
    *;
}

But still I get SIGSEGV in my JNI library.

I looked in bin/proguard/seeds.txt and the variables ARE in there.

But something goes wrong.

The code runs perfectly until I enable ProGuard.

UPDATE: In researching this I am wondering whether the requirement about Android GC being able to relocate pointers is affecting ProGuard. In my native C code I have this:

JNIEXPORT jint JNICALL  Java_com_example_MyClass_my_1native_1method(
    JNIEnv* env,
    jobject thizz)
{
    jobject thiz = (*env)->NewGlobalRef(env,thizz); // prevent newer GC from relocating pointer

Could this be the source of the problem for ProGuard?

androidin

This project involves a main project that incorporates a number of subprojects. It is one of the subproject libraries that calls the native library. I had put the -keep class *; preservation into this subproject's proguard-project.txt. I didn't think it needed to be put into the main project proguard file. But that was the problem. As soon as I duplicated the library subproject's -keep class statement in the main project proguard file then the SIGSEGV disappeared. It would be nice if proguard could make it unnecessary to duplicate entries like this.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can global variables be accessed when using Multiprocessing and Pool?

From Dev

How do I remove "TAG" field from class using ProGuard?

From Dev

How model class is accessed from controllers?

From Dev

How can I define variables that can be accessed from different files using node.js?

From Dev

Does member variables gets retained by block when accessed using self

From Dev

JVM can't find class when using JNI from C++

From Dev

How to preserve children when using cloneElement

From Dev

Variables accessed by a function within a class

From Java

How can "this" of the outer class be accessed from an inner class?

From Dev

Created variable inside for loop can't be accessed when using a class

From Java

In proguard, how to preserve a set of classes' method names?

From Dev

No Items in Populated ObservableCollection when accessed from another class

From Dev

TestContext is null when it is accessed from base class's virtual method

From Dev

How to resolve UnsatisfiedLinkError when using JNI with packages?

From Dev

Java: how to access class variables when using add(ClassName) in a JFrame

From Dev

How to set class level variables in Rails initializer when using spring?

From Java

In proguard, what is the keyword to preserve package/default access variables and methods?

From Dev

How to call class method from JNI and cast the return to a custom class

From Dev

How to keep class with ProGuard

From Dev

When using Firebase, GoogleSignIn is marked as internal and should not be accessed from apps

From Dev

How to call an object from another class - cannot be accessed

From Dev

how say to proguard not obfuscate class and method names when exception occured?

From Dev

Why I can not access private field of a base class when private variables can be accessed this way

From Dev

How to extract data from networking class into variable in same class so that it can be accessed from other class in ios

From Dev

How is the scoreDirector accessed when using the autowired SolverManager with Optaplanner?

From Dev

JNI RegisterNatives() can't find class method after running ProGuard

From Dev

How to remove .html from URL and redirect when the html will be accessed directly

From Dev

How to prevent CSS from overwriting a previous value when using variables

From Dev

How to access Elements of a java class in c++ using JNI

Related Related

  1. 1

    How can global variables be accessed when using Multiprocessing and Pool?

  2. 2

    How do I remove "TAG" field from class using ProGuard?

  3. 3

    How model class is accessed from controllers?

  4. 4

    How can I define variables that can be accessed from different files using node.js?

  5. 5

    Does member variables gets retained by block when accessed using self

  6. 6

    JVM can't find class when using JNI from C++

  7. 7

    How to preserve children when using cloneElement

  8. 8

    Variables accessed by a function within a class

  9. 9

    How can "this" of the outer class be accessed from an inner class?

  10. 10

    Created variable inside for loop can't be accessed when using a class

  11. 11

    In proguard, how to preserve a set of classes' method names?

  12. 12

    No Items in Populated ObservableCollection when accessed from another class

  13. 13

    TestContext is null when it is accessed from base class's virtual method

  14. 14

    How to resolve UnsatisfiedLinkError when using JNI with packages?

  15. 15

    Java: how to access class variables when using add(ClassName) in a JFrame

  16. 16

    How to set class level variables in Rails initializer when using spring?

  17. 17

    In proguard, what is the keyword to preserve package/default access variables and methods?

  18. 18

    How to call class method from JNI and cast the return to a custom class

  19. 19

    How to keep class with ProGuard

  20. 20

    When using Firebase, GoogleSignIn is marked as internal and should not be accessed from apps

  21. 21

    How to call an object from another class - cannot be accessed

  22. 22

    how say to proguard not obfuscate class and method names when exception occured?

  23. 23

    Why I can not access private field of a base class when private variables can be accessed this way

  24. 24

    How to extract data from networking class into variable in same class so that it can be accessed from other class in ios

  25. 25

    How is the scoreDirector accessed when using the autowired SolverManager with Optaplanner?

  26. 26

    JNI RegisterNatives() can't find class method after running ProGuard

  27. 27

    How to remove .html from URL and redirect when the html will be accessed directly

  28. 28

    How to prevent CSS from overwriting a previous value when using variables

  29. 29

    How to access Elements of a java class in c++ using JNI

HotTag

Archive