Different Apks for android using gradle buildTypes - android

I'm trying to install both debug and release versions on same device so trying to add applicationIdSuffix in buildTypes block of gradle file as mentioned in docs. it was not mentioned to create any package and It's saying that package not found error. Please help.
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
def versionMajor = 1
def versionMinor = 0
def versionPatch = 4
def versionBuild = 0
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.edu.gcfapp"
minSdkVersion 21
targetSdkVersion 26
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "default"
Error I'm getting is this..
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDevDebugGoogleServices'.
> No matching client found for package name 'com.edu.gcfapp.debug'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s

It looks like your are using Google Services although you have omitted that from your gradle.
your google configuration file (google-services.json file I think) does not contain any configuration information for com.edu.gcfapp.debug
Go back to your google console and create a file for both your release and debug package names and place them in the relevant build folders.

Related

“package does not exit” error while compiling project after converted from Eclipse

I've converted an Eclipse project for AndroidStudio then I got some errors "package does not exits", it package is library module.
library project's gradle scripts as follows.
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
debug {
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile 'com.google.android.gms:play-services:9.0.0'
}
and the project's gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "xxxxxxxxxxxxxxxxx"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
}
debug {
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile project(':library')
}
It's weird because IDE does not show any errors while coding and can import package properly but when I try to "run" the project, then error occurs.
I would appreciate it if someone could solve this problem.
Edited
Project Structure is like below.
- app (com.sample.apps)
- library (com.sample.library)
Actual Error Messages
package com.sample.library.xxx does not exits // <- My Custom Class. There are hundreds of errors.
Gradle Errors
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
100 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.344 secs
Solved
I solved this by using product flavors.
This is because library project is going to apply proguard and that's why application project can't find package.
I changed 'com:android:library' to 'com:android:application' and move app project as product flavors.

Getting gradle exception after updating to com.google.gms:google-services:3.0.0

Yesterday, I updated my google services gradle plugin to this:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
}
After that, I am getting below error in my devDebug flavour build:
Error:org.gradle.api.GradleException: No matching client found for package name 'com.example.android.dev'
Here are the relevant part of my app level build.gradle file:
defaultConfig {
applicationId 'com.example.android'
multiDexEnabled true
minSdkVersion 16
targetSdkVersion 24
versionCode 47
versionName "1.3.2"
signingConfig signingConfigs.myConfig
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
}
buildTypes {
debug {
applicationIdSuffix = ".dev"
resValue "string", "app_name", "example-debug"
}
release {
minifyEnabled false
shrinkResources false
resValue "string", "app_name", "example"
signingConfig signingConfigs.myConfig
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 16
}
}
This error does not come in my prodRelease product flavour build. How can I resolve it?
In your debug build type you are using this package:
debug {
applicationIdSuffix = ".dev"
}
This message
No matching client found for package name 'com.example.android.dev'
means that your google-services.json doesn't contain this package.
Follow these steps:
Go to Firebase console
add another android app registering also this package
Export again the google-services.json
Re-register your key on console.developers
Finally fixed the issue.
The trick is to add another app to the Firebase console with the debug package name and debug SHA1 fingerprint.
Doing this essentially creates 2 apps but the google-services.json file downloaded from any app contains information about both apps.

Android unit testing: connectedAndroidTest does not execute my test case

I am trying to add some unit tests to my app. I am developing my app in Android Studio
This is what I did.
Added a new package
Created a class in new package which extends TestCase
Added following method to created class
#SmallTest
public void basicTest() {
assertEquals("abc", "abc");
}
Added following to defaultConfig section in build.gradle
testApplicationId "newly.added.package.name"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
Executed following command in Android Studio Terminal
gradlew.bat connectedAndroidTest
But, when I checked the generated html report, it shows that 0 tests were run.
I tried following, but none of them made a difference to the output of gradlew.bat connectedAndroidTest command.
Added an incorrect package name to testApplicationId in build.gradle.
Disconnected device
Why doesn't my test case get executed? What have I missed?
Following is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "my.package.name"
minSdkVersion 12
targetSdkVersion 18
testApplicationId "my.package.name.tests"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':my_sub_module1')
compile project(':my_sub_module2')
compile 'com.android.support:support-v4:21.0.2'
compile files('libs/my_dependent_lib-1-7-4.jar')
compile 'com.google.code.gson:gson:2.3'
}
repositories {
mavenCentral()
}
You should use the following testInstrumentationRunner:
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Also, click Build Variants on the left side of Android Studio, and select
Android Instrumentation Tests
in the dropdown.

Cannot add buildConfigField in productFlavors

In my android{} section I tried to put two different build types for may free and paid app.
Sadly I'm getting gradle error:
Gradle 'android-Transport' project refresh failed: Build script error,
unsupported Gradle DSL method found: 'buildConfigField()'! Possible
causes could be: - you are using Gradle version where the method is
absent - you didn't apply Gradle plugin which provides the method - or
there is a mistake in a build script
This is my android{} section in gradle build:
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
runProguard false
}
}
productFlavors {
free {
packageName "pl.grzeslowski.transport.free"
buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.FREE"
}
paid {
packageName "pl.grzeslowski.transport.paid"
buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.PAID"
}
}
}
And this is my console log:
Executing tasks: [:transport:compileDebugJava]
Configuration on demand is an incubating feature. Download
http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/sdklib/22.5.3/sdklib-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/22.5.3/ddmlib-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.8.3/builder-model-0.8.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/22.5.3/manifest-merger-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/sdk-common/22.5.3/sdk-common-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.8.3/builder-test-api-0.8.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/common/22.5.3/common-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/lint/lint-api/22.5.3/lint-api-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/dvlib/22.5.3/dvlib-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/22.5.3/layoutlib-api-22.5.3.pom
Download
http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.jar
Download
http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.jar
Download
http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.jar
Download
http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.jar
FAILURE: Build failed with an exception.
Where: Build file 'D:\Programowanie\GitProjects\transport\android-Transport\transport\build.gradle'
line: 77
What went wrong: A problem occurred evaluating project ':transport'.
Could not find method buildConfigField() for arguments [transport.product_flavors.MonetizationType] on
GroupableProductFlavorDsl_Decorated{name=free, minSdkVersion=-1,
targetSdkVersion=-1, renderscriptTargetApi=-1,
renderscriptSupportMode=null, renderscriptNdkMode=null,
versionCode=-1, versionName=null,
packageName=transport.free, testPackageName=null,
testInstrumentationRunner=null, testHandleProfiling=null,
testFunctionalTest=null, signingConfig=null, resConfig=null}.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.781 secs
The correct syntax for the buildConfigField lines is:
buildConfigField "boolean", "MY_FLAG", "true"
In other words, the strings need to be separated by commas.
In my case:
buildConfigField ("transport.product_flavors.MonetizationType", "MONETIAZATION_TYPE", "transport.product_flavors.MonetizationType.FREE")

Changing Android versionCode causes build.gradle error

I just upgraded my Android Studio to 1.4.1.
In build.gradle, When i change my versionCode,
import org.apache.commons.lang3.JavaVersion
gets added to the top of build.gradle, which causes the error:
build file '/../app/build.gradle': 1: unable to resolve class org.apache.commons.lang3.JavaVersion
# line 1, column 1.
import org.apache.commons.lang3.JavaVersion
When I remove the line import org.apache.commons.lang3.JavaVersion, it gets added back automatically after a while.
When I revert the versionCode back to 1, the import statement disappears and all is well.
Gradle File
import org.apache.commons.lang3.JavaVersion
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "com.x.app"
minSdkVersion 14
targetSdkVersion 22
versionCode 2
versionName "1.0.1"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
How do i solve this issue?
Thanks!
Simply remove the import.
Your versionCode line in build.gradle should look like this :
versionCode 3
You use this class on compileOptions. That has nothing to do with pour versionCode, which is just fine.
Java 8 is not supported in Android, so I guess your problem is here

Resources