Android Gradle: depends on libraries but is not a library itself - android

I'm working on my gradle build for an android product to get product flavors working.
I have following project structure:
at.mkw.inlocs.android - Library Project
at.mkw.inlocs.android.lib - Library Project - depends on at.mkw.inlocs.android
at.mkw.inlocs.android.login - App Project - depends on at.mkw.inlocs.android
at.mkw.inlocs.android.core - App Project - depends on at.mkw.inlocs.android.lib
at.mkw.inlocs.android.breeding - App Project - depends on at.mkw.inlocs.android.lib
at.mkw.inlocs.android.localization - App Project - depends on at.mkw.inlocs.android.lib
at.mkw.inlocs.android.health - App Project - depends on at.mkw.inlocs.android.lib
Since adding product flavors to all app and library projects, I am getting an exception when building.
I am using the newest gradle artifact (com.android.tools.build:gradle:0.9+) and android build tools 19.0.3
Another problem is, that Android Studio doesn't show the at.mkw.inlocs.android.lib module in project view.
After switching to packages view, the module is visible, but has no content.
I have pasted the build.gradle files:
root build script
at.mkw.inlocs.android
at.mkw.inlocs.android.lib
at.mkw.inlocs.android.login
at.mkw.inlocs.android.core
at.mkw.inlocs.android.localization
at.mkw.inlocs.android.health
at.mkw.inlocs.android.breeding

Looking at the build.gradle at.mkw.inlocs.android, you are using flavors in a library project.
While this is fine, current flavor support in library project is not final and by default the variants are not published (for consumption by other projects) due to some limitations.
To enable it you'll need to do
android {
publishNonDefault true
}
reference: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

Related

Getting Error -> all package the same library [androidx.activity:activity-ktx] in Android app

I have an application
which has several dynamic modules , which are working fine .
I recently updated compile sdk and target sdk to 31 .
Now I want to add new dynamic module which has a external different application (aar file) and associated libs (jar)with it . And this new app is included as a lib in my app dynamic module , when I try to add the implementation for the new app in my dynamic feature module , it gives me run time error :
[:modulename_last , :modulename_first]
all package the same library [androidx.activity:activity-ktx]
all package the same library [androidx.collection:collection-ktx]
.
.
.
.
all package the same library [some api lib]
What could be issue ?
you can try to align those library version between app and feature module, because the app will not align the library version with feature module.
By using ./gradlew :app:dependencies to find out what version of those libraries in your app module, and using ./gradlew :{featureModule}:dependencies to check the version in feature module.
In my case, the version of activity-ktx is version 1.1.0 in my app module and 1.3.1 in the feature module, so I got the same error.
Hoping this information will helps you :)

OSS license plugin doesn't include library module licenses

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.

Assemble gradle flavour compiles dependencies from other flavors

We are trying to develop 2 gradle flavors to speed up our development process:
the local flavor that compiles our libraries as modules
the remote flavor that uses the latest SNAPSHOTS of our libraries
I have declared two flavors in gradle:
productFlavors {
local {}
remote {}
}
For now, let's assume that both our local and remote libraries are available as local modules (for debugging purpose). I have created a sample project here. Since each library has sub libraries that are also supposed to be local or remote, I have added:
dependencies {
localCompile project(path: ':mylibrary', configuration: "localDebug")
remoteCompile project(path: ':mylibrary2', configuration: "remoteRelease")
}
Now it becomes tricky. If I call gradle assembleLocalDebug, I get this line:
:mylibrary2:compileRemoteReleaseJavaWithJavac UP-TO-DATE
In the case of the sample app, it compiles. But in our case, we have a project where the newest features cannot be found in the SNAPSHOTS (since they are not published yet). This shouldn't happen since we are building in local. Is there any way to prevent gradle from compiling the remote flavor?
What you want to do might be solved in the latest versions of Gradle.
With Gradle 3.1, you can now use the so-called "composite builds".
As an example, say you have a library L, deployed on a remote repository, and a project P depending on L. Imagining that both L (say, "libL/") and P ("projectP") are in the same directory on your system, you can build the "local" version by running the following command from projectP:
$ ./gradlew --include-build ../libL build
Moreover, composite builds are coming in Android Studio!

Android Library Project Dependencies and NoClassDefFound

EDIT: This project demos the behavior:
https://github.com/NathanielWaggoner/AndroidExamples/tree/master/packing
There is a read me that explains the first time you build it.
I have a set of projects built using Gradle and AndroidStudio. We'll call them Lib1, SDK and APP. Lib1 and SDK are deployed to a private Sonotype repo that I maintain.
App depends on SDK - App is a normal android project
SDK depends on Lib1 - SDK is an Android Library Project repackaged as a Jar
Lib1 depends on some Android Stuff. - Lib1 is a normal android library project, packaged as an aar.
When I run gradle dependencies In each project i see some things i don't expect.
In Lib1 I see all appropriate dependencies, just as I would expect (including dependencies of dependencies)
In SDK I see all relevant dependencies and their trees except for that of Lib1. In the case of lib1 the only thing I see is lib1, not any of its dependencies.
In APP i see something very simlar to the SDK dependencies - I see all dependencies are their trees, except for SDK. In the case of SDK I only see the SDK. I don't see Lib1 listed as a dependency (or any of the other dependencies of SDK).
Everything builds fine - that is i can compile and deploy Lib1, and compile and deploy SDK. I can compile the APP - however when it uses SDK code which references Lib1 I get noClassDefFound on the Lib1 classes.
Checking the output jars none of the library classes are included in the Jars created during the build phases of SDK or Lib1, and the poms created don't reference any dependencies (from installArchives/uploadArchives tasks).
How do I work around this? I don't want consumers of the SDK to have to directly compile in the Lib1 in order for those classes to be found.
This topic:
http://forums.gradle.org/gradle/topics/using_the_maven_publish_plugin_no_dependencies_in_pom_xml
shows some extremely similar behavior to what it turns out was happening to me - my poms were being generated without their dependency information being included.
For now i've got this work around in my installArchives.`
task installArchives(type: Upload) {
repositories.mavenInstaller {
configuration = configurations.archives
//configuration = configurations.default
pom.version = "0.0.1-SNAPSHOT"
pom.artifactId = "lib2"
pom.groupId = "waggoner.android.examples"
pom.withXml {
def node = asNode().appendNode('dependencies').appendNode('dependency')
node.appendNode('groupId','waggoner.android.examples')
node.appendNode('artifactId','lib1')
node.appendNode('version','0.0.1-SNAPSHOT')
}
}
}

Uploading multiple dependent android libraries to maven central

I have following project structure in android studio
root project
- libA
- libB
- libCommon
- library (empty - just depends on libA, libB, libC)
where all are android library projects and both libA and libB are dependent on libCommon.
Now I am trying to push the entire project to maven central using Sonatype for which i am following this code https://github.com/chrisbanes/gradle-mvn-push
The problem is that only one project is getting uploaded to the Sonatype repo which is happens to be the last one - library blank with no dependencies added.
How can i upload entire project ?

Categories

Resources