Include a file when building Android AAR - android

I have an android project which I can already package into an AAR file using gradle. Now I want to be able to add a license file to the AAR. How can I do this?

Not entirely sure if it fits your needs but I would suggest you use a different solution. Instead of trying to include license information as a separate file, include license information in all of your files. That's a typical way to do it (e.g. look how Google does it in their I/O app: here or here).
This way you will make sure the user of your library will see license information (which you cannot be sure of if you put an external license file in the aar).

if you want to add a LICENSE.txt into your android library (aar), there are two things should be done:
add your LICENSE.txt to your project, path: src/main/resources/META-INF/LICENSE.txt(other resources folders are acceptable as well)
add following code into your module/build.gradle file.
android {
packagingOptions{
merge '**/LICENSE.txt'
}
}
the keyword merge means add all matching files to your aar

Related

File 'root/lib/META-INF/MANIFEST.MF' uses reserved file or directory name 'lib'

I tried to apply for app bundle but I failed.
I can build apk with spilit option but I couldn't make aab.
I put the following gradle option.
bundle {
abi {
enableSplit = true
}
}
The error message in the console is below.
File 'root/lib/META-INF/MANIFEST.MF' uses reserved file or directory name 'lib'.
The file structure that was built is like below.
I heard I have to add the below library, but I didn't.
Actually, there is no difference either I add the play core library or not.
implementation "com.google.android.play:core:$play_version"
I wanna change some options to avoid alias problem but I don't have any idea about that.
Anyone who can handle this problem simply?
Make sure you don't have a directory called "lib/" in your project, since this directory name is reserved in the APK format for storing native libraries.
If not in your project, one your library dependencies must have it and is being copied into the APK.
The reason it works for APKs but not AABs is that the AAB format is more strict and will prevent you from embedding unnecessary files in your app.

Add google firebase as a library

For some reason I do not use Android Studio, I compile my apps using a remote server with apache ant so, Is there a way to add firebase analytics, messaging... as libraries?
Firebase is a set of aar (Android Archive) files. Android Studio gradle plugin will simplify the use of the aar files but you can manually configure the app to use the aars. To do so in addition to linking to the libraries you will need to manually merge the manifest from all aar files to your app manifest. That includes permissions, services, receivers, content providers etc. aar is simple zip file. You can open it with unzip (or any other tool that reads zip files) and see the AndroidManifest.xml. You will also need to merge all the resources (if any) for the aar files. The last step will be to add the google_app_id from the generated google-services.json file as string resource. All in all, this is not a trivial work but it is possible.

Android Private Libraries does not allow modifications to source attachment

I am getting the following error while trying to use the google maps api using googleplayservices in android.
I have added the google play services library as dependency project and declared it in android manifest also.
Please help me i am unable to proceed and i have done every possible solution I found in stakeoverflow to solve this error.
Error:
Official solution is
Allow src/doc attachement for 3rd party jars in libs/
Since those jars
are added dynamically through a classpath container, the devs cannot
set the source path and the javadoc through Eclipse UI (container
don't allow editing those). To fix this, and to make sure that both
paths are picked up not only by the current project, but also by other
projects (if the current project is a library project), the value is
set by a file sitting next to the jar file. The file is name after the
jar file, adding .properties at the end. For instance foo.jar ->
foo.jar.properties It can currently contain 2 properties: src:
relative or absolute path to the source folder (or archive). doc:
relative or absolute path to the javadoc.
Check following question for more details
The Jar of this class file belongs to container 'Android Dependencies' which does not allow modifications to source attachments on its entries

Replace .so file in android apk

is it possible to replace .so file in android app without source code?
I am creating app which use some .so files under LGPL license v2.1 http://www.gnu.org/licenses/lgpl-2.1.html
License says: "...you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it..."
Is it possible to replace .so file and recompile app without source code e.g. in existing apk? I can't give user source codes. Or some option to give user .class files so he can create apk?
Is it even possible and if so, what are options?
Thank you!
Yes, you can replace a .so file in an apk. Just use 7zip to open the apk replace the file and you are done.
About gpl: you should have 2 libraries, one so for your code and one for the code you borrowed, this way the user can replace the so for the library, but your code cannot be changed. You can also put a check for the libs version and just exit if it was changed.

Is library file present in .apk file?

Actually I want to know that if in my application's libs folder, any library file(e.g .jar file) is present, then after installing(running) that application, will library file present in .apk file?
According to my understanding, library FILE should present in generated .apk file. If I am wrong then please correct me.
If my question is below standard, then extremely sorry for that. Any help will be well appreciated
With recent versions of the Android tools, .jar files in the libs folder are automatically included in the build. (See Dealing with dependencies in Android projects.) So, yes, the library is included in the compiled bytecode (not as a separate file).
If you use ProGuard in a release build, then it will attempt to strip out any code which is not actually used. So, it may be that some parts of the library are included in the final .apk, and some parts are removed.
the answer is yes. The apk is just a zipped version of your compiled project. If you open it with winrar for example, youll see that everithing is in there ;)
You can try it and see yourself but you can not directly see the .jar file under libs folder in the apk generated. Library class files are all together are compiled into a single .dex file. If you decompile that dex file, you can reach the java codes.

Categories

Resources