How to add .java files to .apk archive within gradle - android

How to add .java source files of android project to .apk using gradle? Suppose you have been given this android kotlin app sample. How to extend build.gradle.kts to include .java files from ./app/src/main/java/org/gradle/samples/ to the .apk archive during build process? The target should be the root directory of .apk archive.
I've read several posts, such as this and this. But I haven't been able to complete the task yet.

Related

Problem linking .so and .lib on android studio

I'm having trouble linking some files to my project. It's an android studio project and I want to link one external file: "Emv_lib.so" (I know that are some questions on how to link .so files, but those are about internal .so files, this is an external one.)
Beside this file, I have an emv_lib.lib and emvIIapi.h (the header file that actually contains the functions that i need to call). I cannot get this to work. I tried with CMakeList, putting the emvIIapi.h file in there, but it comes with the error: "Execution failed for task ':app:configureCMakeDebug'.
C/C++"
I follow some suggestion, to create in src/main the folder jniLibs and put your .so files in there, but it didn't work.
From my undestanding, I have to compile, somehow, either the .so files or the .lib file.
I'm new to android studio, so don't go hard on me. Thank you for your time!

How to get android.mk file from decompiled APK?

I have an .apk I decompiled and I see there are **.so** files used in that code.
How do I find the **.mk** file from that source code?
You can't.
Build scripts like build.gradle and the .mk, if there even was one, are used to build the .apk but are not included in the output of the build i.e., the packaged .apk

aar vs "plain module" advantages

if I have a project with many library projects linked, could I improve build performances by packaging each of them in an AAR and including it in the main project ? Or this will not make any difference since that when the compiler need to assemble the apk it need to package everything together anyway?
Thanks to any one who will give me some clarifcation about performance differences between the 2 approach
I don't think you will save any build time by wrapping an existing .jar file into a .aar file and using that instead of the original .jar file.
As this SO post notes, .aar files are basically just zip files which may contain a jar file and some android resources.
Also, because .aar files are not precompiled into Dalvik byte code, the build process for your apk file must still carry out that step at least once. So, you won't save dexing time just by wrapping the .jar file into a .aar file either.
If you build a typical Android Studio project (with some Android library dependencies specified in the gradle build file) you can see the directory underneath app/build/intermediates/exploded-aar where these files have been unzipped. That work must still be done by your build machine even though you are using a .aar file.
Finally, as you pointed out, the .apk packaging work must still be done at the end of the build.
I believe the Library projects (which you are using) is the best way to go because of two reasons:
The library project gives the direct access to the code base of the libraries which can be compiled and packaged together with the main app code
In case, multiple .aar files are referenced within the project, then during the apk creation the unpacking, merging of resources and Manifest file will increase the build time.

How to add a folder to a android apk use appt and ant

When I use ant tool for build an android project, I do not know how to add custom folders to the apk file, such as a a folder named "running" under the project root, when I use the eclipse can be directly add to apk. I hope you can give me some help, thanks!
During the build process, your Android projects are compiled and packaged into an .apk file, the container for your application binary. It contains all of the information necessary to run your application on a device or emulator, such as compiled .dex files (.class files converted to Dalvik byte code), a binary version of the AndroidManifest.xml file, compiled resources (resources.arsc) and uncompiled resource files for your application.
I can't figure out why you need to add the folder to apk, well if you are asking about adding it in the project and later to be accessed in the apk then yes you can place it inside the "assets" folder of your project

AAR in Eclipse ANT project

is there any way to use .aar library (with resources) in eclipse ant project? I know that there is no simply way to use .aar format like in gradle, but maybe there is some workaround to unzip it and import it manually?
This solution was helpful for me
EDIT: A .aar file is simply a zip file with the following contents:
AndroidManifest.xml (Required file)
classes.jar (required file)
Res / (compulsory folder)
R.txt (Required file)
Assets / (Optional folder)
libs/*.jar (folder option)
jni//*.so (optional folder)
proguard.txt (optional file)
lint.jar (optional file)
You see, within the .aar file you have everything you need to operate the library in eclipse.
to create library:
CREATE a new project (hereafter library project ) to your workspace. Do not forget to mark it as a library.
Leave empty src folder library project .
.aar Decompresses the file. You can rename it to .zip and unzip or
use any tools.
Copy the file classes.jar into the libs file folder library project .
Res folder replaces the library project with .aar res file folder.
You've created the project that contains almost everything you need.
Now let's see how to configure your project to reference the library project.
In the project you want to use the library (henceforth, project goal ) added as the dependency library project .
Open AndroidManifest.xml .aar within the file and make sure to copy
everything it takes (permits, activities, services, receivers ...)
in the file AndroidManifest.xml project objective .
If there is, copy the entire contents of the folder assets .aar file in the assets folder target project .
If there is, copy the entire contents of the file .aar libs folder
in folder libs target project .
Make a Clean the workspace and recompiled.
http://www.iphonedroid.com/blog/utilizar-ficheros-aar-en-eclipse/#.Vh3krye1Gko
Indeed, aar files are just archive files. So you can unzip it and find jar files along with ressources files. The question have already been partially answered here:
https://stackoverflow.com/a/21485222/1836870
If you want to get the ressources inside your jar, you could try repackage like it's suggested in this answer:
https://stackoverflow.com/a/21417599/1836870
The brunt of the work can be done by a wonderful script called deaar. The gist explains things, but basically you run:
ruby deaar.rb [path/to/aar] [output_directory]
It outputs an almost ready to use library. Next, you need to run:
cd [output_directory]
android update lib-project -p . -t android-xx
Replace xx with the Android version you're targeting. Now put that directory where your build.xml and project.properties are. Finally, add a line like this to your project.properties:
android.library.reference.1=./output_directory
Replace the directory name with the one you created. You can use ".2" and so on for additional libraries. And that's it!
Twitter Fabric(Crashlytics) has a kits-libs plugin for dependencies management http://docs.fabric.io/android/fabric/eclipse.html.
And there's another gradle plugin project https://github.com/ksoichiro/gradle-eclipse-aar-plugin.

Categories

Resources