Android JNI FindClass not finding R.id - android

I am trying to find the value for a resource id. The first step of loading R class fails:
jclass rcl = (*env).FindClass("my/package/R$id");
the value of rcl is NULL. I tried
jclass rcl = (*env).FindClass("my/package/R/id");
which also returns null.
Finding other classes such as MainActivity working fine. Using NDK15. What could be wrong?
Output of javap:
http://siara.cc/output.txt
EDITED:
On changing class name to just my/package/R, I find the following line in the adb log:
exception: java.lang.ClassNotFoundException: Didn't find class "my.package.R" on path: DexPathList[[zip file "/data/app/my.package-1/base.apk"],nativeLibraryDirectories=[/data/app/my.package-1/lib/arm, /system/fake-libs, /data/app/my.package-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/vendor/lib]]

The problem was solved by adding proguard rule like this:
-keep class my.package.R$* { *; }
It appears that proguard obfuscates R class as well.

Related

Gradle migration : Unable to instantiate application ClassNotFoundException. Didn't find class “Application” on path: DexPathList

Gradle migration : Unable to instantiate application ClassNotFoundException. Didn't find class “Application” on path: DexPathList
The problem is similar to this
Please check it to see what is happening.
I want to find other reserved words or other things would make this problem.

java.lang.ClassNotFoundException in android studio

i am trying to add module and but its gvien error like this:
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.anghatechsolution.eww.datetimepicker.SlidingTabStrip" on path:
DexPathList[[zip file
"/data/app/com.anghatechsolution.eww.datetimepicker-1/base.apk"],nativeLibraryDirectories=[/vendor/lib,
/system/lib]]
can any one having idea about this.
This error means, that you are trying to access class, that currently doesn't exist.
Try to check the name of class, you accessing
You can solve it by setting the name attribute to your class like this:
[Activity(Name = "somepackage.custombuttonrenderer")]
public class CustomButtonRenderer: ButtonRenderer
{ }
An explanation is in my answer here: Why is my custom ButtonRenderer not working?

Unable to load class using DexClassLoader, URLClassLoader or PathClassLoader

I'm trying to load a class file from a server and instatiante it using
different class loaders, but without success.
I tried DexClassLoader, URLClassLoader and PathClassLoader. Whatever I do, the only thing I get is a ClassNotFoundException from loadClass method.
First thing I do is to download:
jar file that contains the class file and the sex file
jar file that contains the class file but no sex file
the naked class file
And store it to the apps private storage folder. Then I try to load the class with one of the ClassLoader implementations mentioned above causing in:
Error: java.lang.ClassNotFoundException: Didn't find class
"FormTestView" on path: DexPathList[[zip file
"/data/data/[PACKAGE_NAME]/app_test_folder/test.jar"],nativeLibraryDirectories=[/vendor/lib,
/system/lib]]
Any idea?
Did you convert your .jar file using dx tool in android-sdks/build-tools?
If you did not try that, use this command:
./dx --dex --output yourJarDexConverted.jar yourJar.jar
The resulting yourJarDexConverted.jar file contains classes.dex which is an encrypted file including all the java classes needed by the application distributed as jar.

Java.exe exited with code 1. Xamarin

Trying to make archive for publishing and has this error
Java heap size is set to 1G.PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.client.HttpClient
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
PROGUARD : warning : com.google.android.gms.tagmanager.zzcx: can't find referenced class org.apache.http.HttpEntityEnclosingRequest
PROGUARD : warning : there were 148 unresolved references to classes or interfaces.
PROGUARD : warning : there were 2 unresolved references to program class members.
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1833,3): error MSB6006: "java.exe" exited with code 1.
I made archive for publishing at Friday and everything was ok. Yesterday I have updates and installed them, but this didn't solve the problem
What's wrong?
Problem is solved
create file named proguard.cfg inside Android project in the solution. Right click and set Build Action to ProguardConfig.
I add this to proguard file
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
Make sure you save file as UTF-8 and NOT UTF-8 BOM

Can't enable Proguard on Android project containing jsch lib

I am trying to use Proguard to obfuscate my Android app which makes use of the library jsch-1.50.jar for uploading files to an SFTP server.
When I do an export from Eclipse, I get warnings "can't reference class" and nothing is produced. I have tried all manner of options to tell Proguard to ignore the jsch classes, but it's not making any difference and therefore I wonder if I am misunderstanding how this works. I am not too worried about the optimisation, but I would like the code obfuscated.
I have setup the proguard-properties as follows:
-keep class com.jcraft.jsch.jce.*
-keep class * extends com.jcraft.jsch.KeyExchange
-keep class com.jcraft.jsch.**
-keep class com.jcraft.jzlib.ZStream
-keep class com.jcraft.jsch.Compression
-keep class org.ietf.jgss.*
-libraryjars /libs/jsch-0.1.50.jar
The project-properties file contains an entry for "proguard.config=proguard-project.txt".
The output from the export with duplicates removed:-
Warning: com.jcraft.jsch.jcraft.Compression: can't find referenced class com.jcraft.jzlib.ZStream
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.Oid
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSManager
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSException
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.GSSContext
Warning: com.jcraft.jsch.jgss.GSSContextKrb5: can't find referenced class org.ietf.jgss.MessageProp
Warning: there were 44 unresolved references to classes or interfaces.
You may need to specify additional library jars (using '-libraryjars').
Error: Please correct the above warnings first.
Would very much appreciate any pointers.
Thanks
Mike
After a bit more investigation, I found the following...
I had forgotten to include jzlib-1.1.1.jar in the project with the corresponding
-libraryjars /libs/jzlib-1.1.1.jar
entry in the proguard-properties.txt.
Also to ignore the warning regards references to "class org.ietf.jgss", I tried the suggested method of excluding the referencing class
-libraryjars /libs/jsch-0.1.50.jar(!com.jcraft.jsch.jgss/GSSContextKrb5.class)
but that didn't help. In the end, I went with :-
-dontwarn org.ietf.jgss.**

Categories

Resources