Netbeans, android-maven-plugin and using apklib/aar dependencies - android

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.

Related

Releasing Android Library without NDK dependency

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

How can I export an Android library as .aar & keep my Gradle dependencies?

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.

Does an Android .aar built with Gradle contain dependencies?

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.

Can an Android AAR have a dependency on another AAR when built with Maven?

This is very similar to Gradle for Android AAR Depending Upon AAR, Both In The Same Remote Repository?, but this question is Maven-specific.
If I have an APK project (app) with a dependency on an AAR project (lib1), can lib1 have a dependency on another AAR project (lib2)?
Yes as long as you use a recent version of the Android Maven Plugin that supports that..
Yes.
Using Android Archetypes I created an android-with-test project, and then two android-library-quickstarts underneath it. I had to change the android-library-quickstart projects' packaging from apklib to aar. Then, I make lib1 depend upon lib2, and made my apk depend on lib1. mvn clean install succeeded.

State of Android project dependency management

We are standardizing our infrastructure for Android development and we are trying to incorporate dependency management to our Android library projects. My current track is using the maven android plugin with m2e-android. We have uploaded the Android artifacts to our Artifactory repository with the Android SDK Deployer. We also have an internal framework with a few libraries we can import into our projects and for most part it works fine.
The issue we are facing now is that apklib dependencies containing resource files are hard to set up. The maven plugin can correctly configure the classpath but if the apklib has resource files that needs to be referenced by the parent Android project, Eclipse is unable to find them unless you checkout the Library Project and link it to the parent project through ADT.
After reading m2e-android discussion on issue https://github.com/rgladwell/m2e-android/issues/8, https://stackoverflow.com/questions/6269816/creating-closed-source-android-libraries#answer-6270768 and APKLIB does not get installed in Maven Repo, I'm not convinced maven is the way to go until ADT properly support closed source apk libraries.
I'd like to know how are you handling these kind of dependencies on your Android projects. What strategies are there other than using Maven?
For reference, here's what we have tried so far.
No dependency management. All required jars are stored into the lib folder and pushed to the source control repo. Library projects are set up as subfolders and pushed to the source control repo for each project they are used in. Eclipse project settings are also pushed. Project built with standard ADT Ant script.
Jar dependencies into libs folder and library dependencies as git submodules. Project built with standard ADT Ant script.
Dependency management with maven, including library projects with apklib packaging. Issue with resource files in apklibs.
You can have an insight on how Facebook Android developers address their dependencies issues in this video: How Facebook Built Facebook for Android.
They use Buck for that. Buck is a build system for Android that encourages the creation of small, reusable modules consisting of code and resources. Buck is in github
This might not be the best solution for you but maybe for someone else.
With the advent of Android Studio and Gradle, we are no longer facing issues with project dependencies; Android or otherwise.
Gradle supports Maven dependencies in jar or apklib formats. Popular libraries have been exported to the apklib (aar) format and made available through Maven.

Categories

Resources