Multi Module Android Project Gradle suggestion - android

I have a project A which has 3 B,C and D lib module.
Project A has 4 builtTypes Debug, Staging, Beta and Release but library modules has only debug and release. Now if I want one of my lib module consider C to have 3 buildTypes Debug, Staging and release. How can achieve this?

Go View > Tool Windows > Build Variants.
You can see all of modules with BuildVariants that are combination of BuildTypes and ProductFlavors, and select which type you want use for any module.
for example I define 2 flavors {production,staging} anly for app and remote modules and by default every module have 2 buildType named {debug,release}
and then you run app or install or build apk with selected configs

Related

Android Gradle | how to build debug apk for only active ABI

I'm refactoring my current build.gradle to support both amazon and googleplay apks.
For that I've created 2 productFlavors (amazon and googleplay), so I can set some different dependancies and manifest.xml for each flavor.
During this refactor I came to an understanding that my current gradle didn't work well.
My goal is to get 4 build variants: debug/release-amazon/googlplay.apk.
When I build a debug I want only the current active ABI to be built, but if it's a release build , build all ABIs APKs.
I succeeded to get those variants. But build only current active ABI on debug only, doesn't work for me, because I couldn't get the value of active ABI from gradle.
I couldn't find this information on "Active ABI" on the internet, so this is why I'm asking here.

Local Android Library Modules and com.android.tools.build:gradle:3.0.0

I'm currently working on migrating our project to the new gradle plugin (3.0.0) via the provided migration guide:
https://developer.android.com/studio/preview/features/new-android-plugin-migration.html
In our Android project we have a single library module and 2 app modules. The library module, as it stands, has no flavours and just the debug & release build types whereas the apps have multiple flavors and build types.
What I'm finding is that the buildTypes of the library module have to match those of the app modules exactly. For instance,
If the app module has a buildType called debugProguard, then the library module must also have a buildType called debugProguard. This means that in the library module I end up having to declare the buildTypes with no body:
buildTypes {
...
debugProguard {
}
...
}
(From here:
Android Studio 3.0 Error. Migrate dependency configurations for local modules)
Is there anyway to avoid this? It seems strange that the library needs some knowledge of the architecture of the consuming app.
What I'd like to do, ideally, is to tell the build system to use a certain buildType of the library for a buildType of the app. For instance, for buildType x, y, z in the app use 'debug' in the library, and for i, j, k use 'release'.
Thanks in advance
They've just addressed this in the Canary 7 release of Android Studio 3.0:
You can now specify an alternative build type the consumer should use
from the producer using the android.buildTypeMatching property as
shown below. The plugin uses the alternative build type only if a
matching build type is not found.
android {
…
// Let's say your app configures a 'staging' build type and a library module
// it depends on does not. You can use the property below to tell the Android plugin
// to use a library's 'debug' build type instead.
buildTypeMatching 'staging', 'debug'
}

Android configuration from Jenkins environment variable

I am using Jenkins for CI for my Android Project.
There I am having two build, QA and Dev.
For both some of the configurations are different like url and all which i have in my adroid project.
Now my task is to provide some variable in jenkins, and according to that variable only that apk should be built with required config only. Like if i apply for QA build, so only apk with QA config should be generated.
Is there any way to achieve this?
As far as I understand you have 2 flavors in your gradle file, QA and DEV.
If that is the case you can do that from the configuration of your Job.
In Jenkins go to your Job and then to Configurations
Go to the "Build" section and then to task.
That is a textField where you can define which flavor to compile, for example if you want QA you can define the task:
assembleQARelease
and for DEV
assembleDEVRelease
In the same way you can define if instead of Release version you want the Debug version or if you create any other flavor for your app just Change QA or DEV for this new one.
Also you can add another task before as Clean or even you can define the 3 of them
clean
assembleQARelease
assembleDEVRelease
It will clean the project then create the QA release version and then DEV release.

Android Gradle build resulting apk contains both obfuscated and non-obfuscated classes

When building my android project, I have added the following to the build.gradle file to enable proguard:
buildTypes {
release {
runProguard true
proguardFile 'proguard-project.txt'
proguardFile '../common/proguard-shared.txt'
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
Everything builds okay BUT when I disassemble the resulting dex file, it turns out that both the obfuscated and non-obfuscated files are there.
For example, both common.Base64 and common.a exist, the first is non-obfuscated, while the second is.
Not sure its related, but the project itself has a non-typical structure.
This is a result of us having a large android code base with more than 40 android apps.
We are trying to create a gradle based build flow side-by-side of existing eclipse based build.
If all goes well, we intend to change the file structure to be more native gradle, and start using flavours and build-types to have-away with many of the libraries we created to accommodate for the lack of flavours and such.
Project E above relies on a chain of libraries like that:
E -> D -> C -> B -> A
e.g. The E project depends on the library D which depends on library C ... all the way up to A.
After looking into this, I found out that this is a problem if you first build without proguard enabled and then build it with it enabled. This is due to the incremental mode of dex.
You can do a clean build after enabling proguard and it'll fix this.
Edit: I previously indicated that you can disable incremental mode in dex, but it turns out that actually doesn't help!

Android Gradle Release build libraries

In my Android Studio project I have 2 flavours both having separate corresponding dependencies.
dependencies {
libflavour1Compile project(':TestLib1')
libflavour2Compile project(':TestLib2')
}
Building both of these flavours in debug works great, pulling in their respectful resources.
However, for both flavours debug and release urls are needed. To 'TestLib1' I added strings.xml to the release/res/values folder. Now the build is always inserting this release string to the debug build.
In Android Studio, selecting all build variants to be Debug still results in the release string being used even though the folder is not highlighted.
Creating a Debug build on the command line also has the same result.
./gradlew installLibflavour1Debug
Is there something I'm doing wrong here or do libraries always default to the Release build type?

Categories

Resources