I have a library project - let's call it lib1 which has custom flavorDimensions specified. More precisely there is buld dimension with actual flavors full and production.
This library is used by another library project (lib2) with no custom flavorDimensions specified and app project with dependency to lib2 but not directly to lib1.
To tell lib2 which flavor of lib1 to use I can specify missingDimensionStrategy 'build', 'full'. Great. Mission accomplished, right?
Well not really... Project won't sync because app project doesn't know which flavor of lib1 should it use??? I need to put the missingDimensionStrategy 'build', 'full' to the app project as well. You can imagine that if you try to build a well modularized app. This line will be practically in every build.gradle which transitively depends on lib1.
Is this how it should be? Can't I tell gradle somewhere globally what flavor to use? I wanted to add the dependency with debugApi project (path:':xxx', configuration: 'fullDebug') etc. but that doesn't work... :(
Can anybody give an advice? Thanks.
Related
I built an Android library and published it on Jitpack.io, in this library I'm using some other libraries for debugging purposes such as Facebook Flipper and Hyperion but I don't want to export these libraries, meaning, I don't want these libraries' files to make its way to anyone who is going to use my library, How can I do that ?
Looks like you want to define gradle dependencies based on build or flavor. For example :
debugImplementation "example.debug:dependency"
Now when you build your artifact, you just build a non debug variant and the dependency will not be included.
You can read more here: https://developer.android.com/studio/build/dependencies#dependency_configurations
I have following project structure:
main-project/
modules/
moduleA/
moduleB/
main-project uses moduleA and moduleB as dependencies. Currently, these modules are library modules, however, I would like to be able to release them as standalone applications. Thus, I want to be able to release:
main-project application (dependent on moduleA and moduleB)
moduleA standalone application
moduleB standalone application
There are more submodules than just moduleA and moduleB, so creating application modules for each of them is not an option (unless it is possible to automatize it by Gradle).
Is there a possibility, using Gradle, to build main-project and its dependencies as separate APKs?
EDIT
To better illustrate my problem, here is less abstract example of my project structure:
cats-dogs-browser/
modules/
cats-browser/
dogs-browser/
I would like to release cats-dogs-browser, cats-browser, dogs-browser APKs. Both cats-browser and dogs-browser are able to work as standalone applications (they have own resources, activities etc.). Using flavours in cats-dogs-browser to include only one of modules is not an option as it contains a lot of logic that is not needed for cats-browser nor dogs-browser to work.
I know I can do it by providing application modules for cats-browser and dogs-browser (or using one such module with flavours), but in real project there is a lot more than 2 such modules so I am looking for better solution.
Have you tried to include another productFlavor with your module id?
Dunno if it's exactly what you want.
I can create 2 different applications sharing part of the code using the following gradle configuration:
flavorDimensions "Applications"
productFlavors {
Application1{
dimension "Applications"
applicationId "com.example.app1"
versionCode 1
versionName "1.0.0"
}
Application2 {
dimension "Applications"
applicationId "com.example.app2"
versionCode 1
versionName "1.0.0"
}
}
I have an AAR library that I want to distribute to partners along with a sample project that uses it. I want to also use the same sample project for manual testing while developing the AAR library. Thus, I would like to be able to use the library project as a dependency when developing, and the AAR file as a dependency when distributing.
I tried to define two flavors in the sample application:
productFlavors {
aar {}
project {}
}
...and then define dependencies like this:
dependencies {
//other dependencies
projectCompile project(':myLibrary')
aarCompile 'com.example.mylibrary:myLibrary-release#aar'
}
The aar flavor builds if I comment out the dependency for the project flavor, but if I leave both uncommented, Gradle sync fails if the myLibrary directory is not present - despite the fact that the project build flavor is not part of the current build variant.
What is the correct way to do this? Or do I have to choose between creating a whole separate project for distribution or always referencing the AAR even when debugging/testing?
I am a plugin developer, my plugin have dependency of two aar libraries. When i am exporting as aar archive my dependent libraries not part of it.my project structure is like below mentioned
App
lib1
--aartool
lib2
lib3
lib1 has the dependency of lib2, lib3 and aartool files.
App has aar dependency of lib1.
Lib1 using some of the customized components from aartool after that lib1 as converted to aar and used to application.But, whatever file we accessed from aartool which is not available in application and throwing classnotfoundException
Is there any way to implement these dependencies as aar?
Always i need to carry lib1 aar to application, i don't want to carry all other dependencies.
I am not sure I understand it correctly, but I believe you just need to add transitive dependendcies like in this question or in this.
Example:
compile ('com.foo:FOO:1.0.0#aar'){
transitive=true
}
If you have circular dependencies you may encounter serious problems! I strongly recommend you to fix this.
I have a main Android project, which depends on a submodule.
The main project has flavors defined in Gradle.
Also the submodule has a few flavors defined. This should be logical - to be able to have flavors for both projects.
For example in the submodule:
productFlavors {
flavorName {
}
}
But this does not work - The build crashes with a message saying that submodule resources are not found in the main project.
But when I delete flavors from the submodule, everything works fine.
It seems to mix the build order when flavors are defined for the subproject, could this be true?
What am I missing? Is it even possible for both main and sub projects to have flavors?
When you reference your sub-modules as dependencies in your build.gradle file, be sure to specify which flavor of the sub-module you are referring to:
dependencies {
compile project(path: ':module', configuration:'yourflavorDebug')
}
then be sure in your build variants, you are building the flavor your main module depends on, and everything should work out.
Also be sure the libraries you are referencing have this in their build.gradle as well:
publishNonDefault true
Without it android studio doesn't seem to be able to depend on flavors of that module. More information here.