I am building a .aar Library that is partially written in C++ and uses OpenCV.
When i am assembling the Library i get a .aar with everything included and i can import it into a different project. When building the project i get the error, that i still need the correct ndk in the project which imports the .aar. This is not good if i want to give the library to others.
Shouldn't the JNI part of the library already be compiled so i don't need the NDK if i already have the .aar?
How can i remove the dependency from the .aar?
Edit:
The Error is No version of NDK matched the requested version 20.0.5594570. Versions available locally: 17.3.6528147, 21.0.6113669
I include the .aar by putting it in the libs/ folder in the module and adding '*.aar' to the build.gradle fileTree implementation.
The reason for it was the automatic stripping of the native part of my library.
Explaination here: https://stackoverflow.com/a/62320616/4284799
Solution 1: Change gradle version in the projects build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
Solution 2: install a ndk and set it in the local.properties
ndk.dir=/path/to/android-sdk/ndk-bundle
Related
After migrating to Android plugin for Gradle 3.0 the OSS license plugin (https://developers.google.com/android/guides/opensource) no longer includes the licenses from the project's library modules dependencies. Only the "app" module.
I'm using com.google.gms:oss-licenses:0.9.1 and com.google.android.gms:play-services-oss-licenses:11.8.0
If I 'apply' the plugin to all my modules, the third_party_license data is generated in the raw folder for each module. But in the end only the data from the app module end up in the APK.
Is there any workaround for this problem?
Yes that is correct.
Based on my search on how the plugin works, the plugin would generate the data into the res/raw folder of the artifact (aar or apk, but not jar files) based on POM files it can get from the libraries. Then the rest of merging is done by Gradle Android Plugin, and not by the OSS License Plugin, which merges the res folders from all of the sources (dependency libs, modules, main app etc.). However here's is the issue, upon merging, the Android Gradle Plugin would choose one if there are duplicates of the same resource (link to explanation), and the one that is chosen is based on a priority, meaning since both the app module and the lib module are generating the R.raw.third_party_license resource which are duplicates, the one from the app module has a higher priority of being included than the one from the module hence the license information from the module are not included.
There are several ways of fixing this:
Include the same dependencies from your library module in your app module. This is probably the worst idea to do but it does not affect your app since Gradle would automatically resolve the dependencies without any issues especially if they will be of the same version, if they were of different versions then Gradle would choose the latest.
Rather than using a module dependency, publish the module to a maven repo (locally or remotely, here's a link to show how it could be done locally), and add it's dependency as such: implementation 'com.mygroup:library:1.0'. Don't forget to remove it from the project build.settings file. This would generate the POM file of the library module and hence get the plugin to read it and include it's library licenses. This means that the library should be compiled and published before compiling the app module, but also it could lead to some weird compiling issues and confusions when errors happen.
Unfortunately there is one more way that I thought would work however it didn't. It is by changing the dependencies in your library module to api instead of implementation. This would expose the library dependencies into the app module dependencies but would increase the build time of the project. But finally it didn't generate the raw resources properly because it seems that the OSS License Plugin only reads the dependencies from a POM file of library and in this case the POM file is not being generated even if the library module dependencies were exposed. Probably should post this as an enhancement or bug request to the developers of the plugin.
I have an Android module from which I export an .aar file.
I imported this .aar with Android Studio Wizard, project compiles, but crashes at runtime with "java.lang.NoClassDefFoundError".
I checked with debugger, Class.forName("retrofit2.Retrofit").. not found.
After unzipping the .aar & checking the classes.jar, I see only my packages, clearly it didn't packaged the libraries I was referencing in build.gradle (ex: Okhttp, Retrofit, Gson.. ).
What I want is a way to keep my build.gradle dependencies. I would prefer it to be packaged into the .aar if possible, else what is the option? Force the client to add in his own gradle my dependencies?
Extra info: I only have gradle dependencies, no jars.
Distribute the AAR via an artifact repository. The metadata in the artifact repository (e.g., the POM file) will contain the information about your transitive dependencies. It also will have information about the version of your AAR, so that consumers of the AARs have clear information about what version they are using. This is how nearly everything else that you are using is distributed: support libraries, Retrofit, etc.
Not sure why I can't find any answers on this. If I convert my library project into an .aar using Gradle in Android Studio, does it retain all the dependencies of that module?
I'm asking because I'm trying to use a Gradle generated .aar locally, but it looks like only some of the original dependencies have been packaged. Namely, it complains that I'm missing 'OkHttp', but if I add it to the main project I get duplicate class errors.
Usually a library does not directly contain its dependencies. This does not matter whether it is an aar or a jar. Instead, the library declares its dependencies in the Gradle build file and they are resolved when someone uses the library.
I built my own android libs in aar/apklib format and I am now looking for a way to use them in the final apk project within netbeans without breaking the maven build. Problem is: I need to include the produced lib jars in order to make netbeans happy about finding imports for the libs, however that breaks the maven build because dex finds duplicate build configs because the libs have been specified twice in pom.xml (once as apklib/aar and once as jar).
Setting the .jar dependency to provided scope fixes the issue.
I'm using the new Android build system that is based on Gradle, together with the early access preview Android Studio. Now, I have two projects: an Android library project, and an Android app project (basically a demo for the library).
In the library project I have added a dependency to the gson library, so my build.gradle file looks like this:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.code.gson:gson:2.2.+'
}
Still, everything works fine and dandy and I'm able to use gson in my library and then my app. But I want to understand where this library is embedded. I've opened both the .aar that is built by the library project and the .apk of the demo app. I was expecting to find the jars for the two dependencies in at least one of these, but I didn't.
So where are they?
From Android Tools website:
These items, plus the output of the compilation of the project’s own source code, are sent to dex for bytecode conversion and inclusion in the final APK.
In other words, they are in your *.dex file inside the APK.
As #SharkyXTS said, the code from any external dependencies is compiled into the final .dex file inside your APK. The reason why you can't find any references to these dependencies in the .aar is because there aren't any.
The .aar format is only supported through Maven for now, so dependencies are found through there. I believe there are plans to eventually support local .aar dependencies (without Maven), but the Android plugin isn't quite there yet. You can see this issue for more information.