I have an apk debug file and a zip file with same contents. There are some .dex files META-INF, AndroidManifest.xml and so on. Is there any way to import it to an android studio project to edit app classes?
Yes, but it's going to be a hassle to do.
The JADx GUI can open an APK and will decompile all classes and resources in a read-only mode. You can then use the "Export to Gradle Project" function to do exactly what it says.
However, it's not exactly reliable. Sometimes it doesn't extract so you need to do it again. When it does finally create a project, you'll notice that the Gradle version is sorely outdated, so you'll need to update it.
Other things to note:
If the project uses libraries, they will be integrated into the project tree in Android Studio. This is because libraries are built into the APK during compilation.
There will be potentially thousands of duplicated resources that you'll have to manually delete.
There will be invalid resource folders
There will be invalid Java code:
JADx can't decompile everything, and will leave empty methods
If there are multiple anonymous classes of the same type used in a class, JADx usually only decompiles one.
As someone who's done this, it's honestly easier to just learn Smali and use APKTool.
Related
I have an android app project. I have a Java class with a main() method that I need to run and that main() method needs to have all of the classes and dependencies from the android project in the classpath.
However, all of the tasks to build the android app will produce an android-compatible output which means that all of the classes that I need are smashed down into .dex files so that the android system can read them.
I need to build all of the code/dependencies for my android app project BUT NOT DEX THEM.
Is there a task I can call that will produce the compiled classes/jars/etc without smashing them into dex files? Like, perhaps the task that comes right before dexing?
Or is there a way I can create a specialized build task that will disable dexing all together so that I can just produce all the classes/jars in normal Java format, so that I can then include those as my classpath when I call my main() method?
I'm very, very new to gradle, so if you answer please try to be specific because I likely am not able to make logical jumps or inferences if your answer is advanced. I've spent like 2 weeks trying to learn gradle to figure out how to solve this problem (which at its core is because there is a bug in the latest version of Android Studio. In previous versions, Android Studio would generate the gradle code needed to run this with the appropriate classpath, but the latest version of Android Studio is generating gradle code that uses deprecated properties and so it horks).
I've been able to figure out how to create a jar of just the classes from my personal code, but it doesn't include the classes from all of the dependencies/libraries.
I've tried 100 different iterations of various gradle configurations and attempts. I don't really have gradle code that I can provide as an example of what I'm trying to do, because I can't seem to find anything close.
Gradle 7.3.3
In other words...
My app code is in com.kenny.stuff. That code depends on com.j256.ormlite which depends on android.* and/or androidx.*.
When my android :app project builds, it will produce app-debug.apk, which DOES NOT contain the .class files for com.kenny.stuff, com.j256.ormlite, androidx.*, etc.
During the android build process, the .class files are smashed down into .dex files because the android dalvik system needs them in that structure. So, the apk contains:
app-debug.apk:
/META-INF
/classes.dex
/classes2.dex
/classes3.dex
and inside those dex files are the smashed together .class files.
but what I need is a jar that is:
what-i-need.jar:
/META-INF
/com/kenny/stuff/Stuff.class
/com/kenny/stuff/OtherStuff.class
/com/j256/ormlite/ORMLiteStuff.class
/com/j256/ormlite/ORMLiteOtherStuff.class
/androidx/*.class
etc.
So, I need to be able to compile and collect dependencies for my android project BUT NOT smash all those .class files down into .dex files.
Context: I use ORMlite in my project, which is a 3rd party library that uses #DatabaseTable annotations on Java classes in order to create database tables that are mapped to the objects. ORMlite relies on a config.txt file which describes the table mappings. That file needs to be generated by one of ORMlite's methods. In order to run it, I need my classes and ormlite in the classpath. ormlite needs the other android classes in the classpath.
I used to be able to do this with a simple feature in Android Studio, wherein I could create a Run Configuration that would let me have all of those things in my classpath and run a main() method which contained the code to generate the config.txt file. However, the latest version of Android Studio has a bug and the gradle code it generates for that Run Configuration crashes. So I need a workaround in which I can run a java class's main() method with all of those app classes in my classpath.
I've downloaded some jar files (e.g. gson-2.8.5.jar) and want to add them to visual studio code locally without any extra downloads so I can benefit from autocomplete feature of classes and methods, How should I do it?
I've searched a while in google and could not find anything useful, so even links to other answers is appreciated.
As suggested by LeoZhu-MSFT which references this in comments all I had to do was open only the folder containing stand-alone Java files and if necessary put any jar dependency in a lib subdirectory (I was previously opening all directories with code snippets I work on in different languages as playground).
I have pretty much no experience with Java so I apologies if I'm not too clear.
I'm trying to create an Android application that uses another package. I only have the source code .java files from the package, which are all part of com.X.Y
I have saved this in a folder called "Database" which I have zipped and added to the build path, so it now appears under "referenced libraries" in Eclipse. However I don't know how to include this, it's not finding import com.X.Y, and I am unsure of what to do next.
I'm a little over my depth in this project, any help would be greatly appreciated
Create a folder structure com/X/Y within your source folder and put your .java file inside of that
Step #1: Move the classes out of "Database" and into the main source tree of your project.
Step #2: There is no step #2.
I strongly recommend that you step away from Android for a while and learn Java separately. There are tons and tons of materials to help you learn Java, including lots of free stuff online. Here is a blog post where I point out a number of topics in Java that Android developers need to learn.
If you want to include those files as an external library I would look at creating a proper jar of the compiled code you want to include instead of just zipping up the source. For you the easiest way would probably be to create a second project in Eclipse, compile it and use the resulting jar.
Once you have the jar, put it in the libs subdir of your Android project. I believe that's enough to get the Android ant target to work...although for Eclipse to be happy I believe you will also need to add it to your Java Build Path.
Or if you are hell bent on just including raw source you may as well just copy/paste the entire package source into your android source directory.
hi i am a new android developer. When i am searching for a logic related to my app in google, i found a java application which is related to my android app. After making some changes i succeded in getting output, but i need the code to be in an android based project. When i change to convert it i get lot of errors, is there any possible way to convert the java application into an android app by including any external jar file..... The java application is just a part of my android app, based on that i have to develop more so pls help me....
thanx in Advance
If you intend to include external Java code via .jar files, that is supported in Android. Just put the file into the libs/ directory of your Android project and use the classes as you would somewhere else.
If you are using Eclipse IDE, this might help:
After including the .jar files in the libs/ folder, right click on the required .jar file and select "build path", then click on "add to build path". After doing this, u'll notice that the .jar file is added in the "Referenced libraries" in your project. Once done, you are all good to go and import methods from these files. Hope that helps you remove your errors. Happy coding. :)
I am developing a library for Android applications which does not use native code (JNI). I have tried suppling the library as an external jar in my Android projects but this method does not include the library contents in the apk and thus throws class not found errors when run in the emulator or device. I have also tried creating the library as an Android project in itself and this does work, but only for public static properties (not methods). With the library and application both being in separate apk's I can see that the VM notices references to the library and can read some properties, but when an attempt to instantiate a class in the library is executed I get class not found even though I can read the public static properties from it (very frustrating!!).
I realize that Davlik byte code is not the same as Java byte code but I am having trouble even finding good information about how to solve what would seem to be a very simple issue in Android. I am looking into the old PlatformLibrary stuff right now but I am not convinced this will work either since the sample has been removed from the Android site :(
So help me out if you can, if I find the answer before this happens I will share it.
viva la Android!
I have tried suppling the library as
an external jar in my Android projects
but this method does not include the
library contents in the apk and thus
throws class not found errors when run
in the emulator or device.
Put the JAR in your libs/ directory, and it will automatically be included in the APK.
This sample project from one of my books shows using the BeanShell JAR this way. Also, all of the GitHub repos starting with "cwac-" on my GitHub page are projects designed to build JARs to be included in Android projects via the libs/ directory.