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.
Related
hi im trying to upload my app to the playstore and have no problems uploading it.
My unic problem is with the app name in all the instance off the project so when i uploaded my app. i recive this errors
`
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sistemasadir.manufacturasadir/com.sistemasadir.manufacturasadir.MainActivity}: java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/androidx.test.tools.crawler-uUxiqPmONbssowJxE5md0Q==/base.apk", zip file "/data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/base.apk", zip file "/data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.en.apk", zip file "/data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.x86.apk", zip file "/data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/androidx.test.tools.crawler-uUxiqPmONbssowJxE5md0Q==/lib/x86, /data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/lib/x86, /data/app/androidx.test.tools.crawler-uUxiqPmONbssowJxE5md0Q==/base.apk!/lib/x86, /data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/base.apk!/lib/x86, /data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.en.apk!/lib/x86, /data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.x86.apk!/lib/x86, /data/app/com.sistemasadir.manufacturasadir-2Hnmo-MIgegbBa5SFRUVEg==/split_config.xxhdpi.apk!/lib/x86, /system/lib]]] couldn't find "libflutter.so"
`
So all my app name distributed in all the android folder now have the name so i dont not why is throwing me this error
i tried changing all the manifest, the dependency of rename the bundle id and all to use the same name but its throwing me the same error.
So the app i downloaded in internal testing and works well but still having this error
I am developing an Android Cordova plugin with local JAR libraries.
The JAR libraries are copied by Cordova into my app/libs folder (following the answer to this question: How do I properly include an external jar file for a cordova plugin?)
The Cordova app builds and runs but one class (ContextFactory), which is present in a local JAR file, fails to load:
java.io.IOException: Can't read Device Description(Provider ae.com.sun.xml.bind.v2.ContextFactory
not found / Cause: java.lang.ClassNotFoundException: Didn't find class
"ae.com.sun.xml.bind.v2.ContextFactory" on path: DexPathList[[directory
"."],nativeLibraryDirectories=[/system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]
At first, I had the plugin run in the standard WebCore thread. After switching to a seperate thread (via cordova.getThreadPool().execute()) the class sometimes loads (non-deterministically) but only when I debug with several break points active.
By debugging into the relevant place (java.lang.ClassLoader), the AndroidStudio debugger informs me that the classLoader is
dalvik.system.PathClassLoader[DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib, /system/vendor/lib, /system/lib, /system/vendor/lib]]]
More specifically, in the AndroidStudio-decompiled bytecode of (java.lang.ClassLoader from SDK Android 29), the method call
url = findResource(name); (line 793) finds a resource non-deterministically. If url remains null, the exception will be thrown, if a url is found, the class loads successfully. (url in the good case evaluates to jar:file:/data/app/name.of.my.app-1/base.apk!/META-INF/services/ae.javax.xml.bind.JAXBContext where ae.javax.xml.bind.JAXBContext is another class in the JAR file)
I assume that the "." directory refers to /app/ and so I wonder if I have to configure my project to include /app/libs/ somehow as well. If so, how can I do that?
Apparently, the library can be loaded if I run the plugin on the UI thread. cordova.getActivity().runOnUiThread()
We use a custom Android ROM which in-turn uses the default WebView with version 48. We want to replace that APK with the APK from the Play Store with version 74. Both have different package names.
I've read this replacing default WebView and done changing my frameworks/base/core/res/res/values/config.xml values to point to the new APK's package name.
Now, when I try to launch the Activity which hosts the WebView I get this stacktrace
E/webviewchromiumloader: Failed to open relro file /data/misc/shared_relro/libwebviewchromium64.relro: No such file or directory
E/dex2oat: Failed to create oat file: /data/dalvik-cache/arm64/data#app#com.google.android.webview-1#base.apk#classes.dex: Permission denied
E/cr_LibraryLoader: Unable to load library: webviewchromium
E/WebViewFactory: error instantiating provider
Binary XML file line #7: Binary XML file line #7: Error inflating class android.webkit.WebView
What am I missing here? or any alternative library which has the latest WebView
Solved here - link
For the purpose of developing an Anti-malware on Android, I need to have the smali representation of an APK.
I'm trying to execute the the baksmali.jar directly on the device. I asked the author of the tool GitHub: Executing baksmali on an Android device.
I followed the steps according to the post
Stack overflow: How to execute the dex file in android with command?
I downloaded the v2.2b4 version
dx --dex --output=classes.dex baksmali.jar I used the dx tool from android/Sdk/build-tools/25.0.2
zip baksmali.zip classes.dex
adb push baksmali.zip /sdcard/ I'm using a genymotion emulator custom phone-4.4.4 API 19
adb shell mkdir /sdcard/dalvik-cache
adb shell ANDROID_DATA=/sdcard dalvikvm -cp /sdcard/baksmali.zip org.jf.baksmali.Main
After that, I'm getting this error message Unable to locate class 'org/jf/baksmali/Main'
Precisely
Unable to locate class 'org/jf/baksmali/Main'
java.lang.NoClassDefFoundError: org/jf/baksmali/Main
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jf.baksmali.Main" on path: DexPathList[[zip file "/sdcard/baksmali.zip"],nativeLibraryDirectories=[/system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 1 more
Suppressed: java.io.IOException: unable to open DEX file
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:296)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexFile.<init>(DexFile.java:59)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:263)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:230)
at dalvik.system.DexPathList.<init>(DexPathList.java:112)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:48)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:38)
at java.lang.ClassLoader.createSystemClassLoader(ClassLoader.java:116)
at java.lang.ClassLoader.access$000(ClassLoader.java:65)
at java.lang.ClassLoader$SystemClassLoader.<clinit>(ClassLoader.java:81)
at java.lang.ClassLoader.getSystemClassLoader(ClassLoader.java:125)
... 1 more
I don't understand this error, the classe path is correct.
How can I fix this ?
Thank you in advance.
After moving around, I finally found the solution to the following problem:
" execute the baksmali.jar in an android device, ideally the execution is launched by an application targeting another application."
So, lets say we wont to develop an application that is able to "baksmali" (disassemble) another application, without requiring any special permission.
These are the steps to get the job done:
download the baksmali.jar v1.2.3
add the jar to the app/libs directory of the android studio project
right click on the jar and select the option "Add it as a Library"
(use the "Project->project" view to see the libs directory, you may not see it in the "Project->android" view)
you can use the org.jf.baksmali.main.mainmethode by passing the CLIarguments to that method using a String[]
Here is a helloWorld App illustrating the use cas:
GitHub: Baksmali Hello world
After launchig the application you should see folders in the /data/data/com.example.bartman.baksmalihelloworld/<name_of_baksmali_output>
The DexClassLoader contructor looks like this:
public DexClassLoader (String dexPath, String optimizedDirectory, String libraryPath, ClassLoader parent)
What does DexClassLoader expect to be passed for libraryPath (besides null)?
Is it possible to pass in an external library as a parameter to DexClassLoader? If so does the libraryPath parameter behave similar to java's -classpath cmd line option? I wrote a simple java application that references a jar file as an external library, now I want to replicate the behavior in an android app.
I have a jar with math functions: MyMath.jar - contains a class "Add" and a method "add". In my main program I import the "mymath" package from MyMath.jar, create an instance of the Add class and call its add method.
To build I use:
javac -classpath ../lib/MyMath.jar MainProgram.java
To run I use:
java -classpath .;../lib/MyMath.jar MainProgram
This successfully utilizes the MyMath.jar to access the "Add" class in my main program. Now I need to replicate this in an android app, but I am unable to successfully load MyMath.jar with DexClassLoader, here is my implementation:
DexClassLoader classloader = new DexClassLoader("/storage/sdcard/Download/MainProgram.jar", codeCacheDir.getAbsolutePath(), "/storage/sdcard/Download/MyMath.jar", ClassLoader.getSystemClassLoader());
I can instantiate classes and invoke its methods that do not depend on "MyMath.jar" with classloader, but I cannot invoke methods that do depend on MyMath.jar
Here's the thrown exception when I try to invoke a method that depends on MyMath.jar:
java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
...
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mymath/Add;
...
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mymath.Add" on path: DexPathList[[zip file "/storage/sdcard/Download/MainProgram.jar"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
How can I link MyMath.jar library when I load MainProgram.jar using DexClassLoader?
This library might help: https://github.com/simpleton/dalvik_patch/blob/master/inject_secondary_dex/src/com/example/dex/DexInjector.java
First, you can turn your jar file to dex file, by
dx --dex --output ./MyMath_dex.jar ./MyMath.jar
And then, you can load your dex file in Android, for more information, you can read the source code in library above.
DexClassLoader's first parameter takes in "list of jar/apk files containing classes and resources, delimited by File.pathSeparator, which defaults to ":" on Android"
The solution was to simply concatenate my MyMath.jar to my MainProgram.jar:
final DexClassLoader classloader = new DexClassLoader(
"/storage/sdcard/Download/MainProgram.jar" + ":" +
"/storage/sdcard/Download/MyMath.jar",
codeCacheDir.getAbsolutePath(),
null,
ClassLoader.getSystemClassLoader());