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.
Related
Whenever I install Gradle third-party dependencies, my android studio project doesn't recognize the library classes. For example, I've tried installing a library called fuzzydateformatter. Android studio doesn't recognize the classes from that library. I've also tried installing other third-party libraries but the same thing happens. Only google and androidx libraries seem to work fine.
// Time Formatter
implementation 'si.virag:fuzzydateformatter:1.1.0'
PS: I'm new to android and I use kotlin
That library has not been updated in six years. It is only published on JCenter, which has threatened shutdown a few times. As a result, JCenter is not included as a repository in modern Android Studio projects.
The best solution would be to use another library, one that is actively being maintained.
If you insist on using this library, your choices are:
Use the source code of the library directly, copying it out of GitHub into your project, or
Adding jcenter() as a repository, in the same spot(s) in your project where you have google() and mavenCentral() (e.g., repositories closures in your project-level build.gradle file)
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.
Ok, so, I'm developing an app for the Amazon FireTV, so I have to use Eclipse.
I'm trying to use this socket.io Java client library: https://github.com/nkzawa/socket.io-client.java
at the bottom of this post, i included the installation instructions, which I'm not really sure how to make work with my existing Eclipse project (I'm new to maven). so from my understanding, do i just add a pom.xml file and a test folder? Then paste in their "maven central code" into the pom.xml? Will this cause any issues with the other code in my project? Or, can I just copy and paste all their SRC code into my project, since it's MIT licensed? I'd rather learn how to do this the proper way. The project is not in JAR format, so I was thinking maybe copying the folder structure into my project then using the Project Properties, Add Library option to connect to my code? Maybe?
Their installation instructions, (available in their readme.md):
The latest artifact is available on Maven Central. Add the following dependency to your pom.xml.
<dependencies>
<dependency>
<groupId>com.github.nkzawa</groupId>
<artifactId>socket.io-client</artifactId>
<version>0.3.0</version>
</dependency>
</dependencies>
Or to install it manually, please refer dependencies to pom.xml.
Add it as a gradle dependency for Android Studio, in build.gradle:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
So, I learned that Maven Central has JAR files available for download. That way, you can just include them in your project via the Project Properties dependencies options. Without having to learn Maven.
You need to first understand how Maven works (and what pom.xml stands for). Maven is a tool that helps you automatically install dependencies (files need) for a given project. E.g if a project needs to process json files, it will need to "import" a json library which will then be a dependency for that project. When you add the dependency file above to your project, and run Maven install, it goes and fetches all the dependencies for your socket.io-client to work.
Unfortunately, Maven does work very well in building android application projects and can be fairly complex to setup correctly (from my limited experience). I would advise that you manually download the jar dependencies and then add them to your android classpath if you are not keen on investing a lot of time learning to use Maven.
To manually install the files .. you can create a default maven project (http://www.tech-recipes.com/rx/39279/create-a-new-maven-project-in-eclipse/) in eclipse, add the dependency file above to your pom.xml and run Maven-install. This will download the dependencies you need to your Maven local repository. You can then copy them from there to your android project.
Regarding installing the socket.io client you can find more on these steps here
http://denvycom.com/blog/socket-io-java-android-without-maven/
I am switching from Eclipse to Android Studio. I have couple of 3rd party libraries that I have added features or modified a little bit. Since the libraries in Eclipse are also projects and we can access the code, I had no problem.
In Android Studio compile tag in dependencies is great but in my case I cannot use it unfortunately.
I fork the project and made necessary changes and add the project as a module in Android Studio. Since the library project already has settings.gradle and example and library modules, there is a mess in my project and it does not compile at all.
Has anybody experienced such a problem? What to do and what is the correct way to forked libraries?
What we've done in my project is create gradle scripts for our dependencies that don't have them, and modify the gradle scripts for dependencies that do have them. Gradle does not play very well with modular dependencies, unfortunately: Each sub-project must know its place in the larger overall project. Since you've already forked the github project, modifying it further shouldn't be a problem.
I have created a new Maven project, using android-quickstart artifact Id. There is no error and apk runs on a mobile phone - okay.
When I download Holoeverywhere project from git and link it with my project as a library, it also works.
But I want to link Holoeverywhere to my project using Maven (pom.xml). It's better to import everything using pom.xml than Import->...Use Library...
Dependency in pom.xml itself shows no error, but pom.xml shows this error:
Same error shows up in all projects with apklib dependency in pom.xml. Some projects need these types of dependencies and I can't use them.
Does m2e-android 0.4.3 really support apklib?