Upload apk to existing play store project after adding flavors - android

I want to upload a new version of my app, but I can't because I added flavors so the package name has changed from:
com.myapp.android
to
com.myapp.android.flavor1
Inside my build.gradle:
productFlavors {
main {
applicationId 'com.myapp.android'
versionName '1.0'
versionCode 4
}
flavor1 {
applicationId 'com.myapp.android.flavor1 '
versionName '1.0'
versionCode 5
}
}
If I change the applicationId of flavor1 to 'com.myapp.android' I get this error:
Error:Execution failed for task ':app:processMainDebugGoogleServices'.
No matching client found for package name 'com.myapp.android'
So my question is, should I try to fix that error (and if yes how?) or is there any other work around ?

I haven't tried this, but reading the docs it seemd that just taking "applicationId" out of both flavor sections (main and flavor1) should work fine.

The new applicationId should be in your google-services.json as well.

Related

Google Play Developer API version_name

I'm trying to automate publishing an app to the Google Play store using the Gradle Play Publisher. So far so good except that I haven't been able to update the version_name this way, it just ignores it.
I Tried ./gradlew publishRelease -Dversion_name=3.0.0. It looks like it's due to Google Play API limitations. If I run ./gradlew assembleRelease -Dversion_name=3.0.0 to generate the apk and then upload the apk manually it correctly uploads with the version 3.0.0. Just want to make sure is it not possible to upload the version name vía Google Play Developer API or is it an issue of Gradle Play Publisher?
build.gradle
def version_name = System.getProperty("version_name")
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode version_code
versionName "${version_name}"
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
EDIT:
Following R. Zagórski suggestions I tried:
1.
./gradlew assembleRelease -Dversion_name=3.0.0 publishRelease
and
2.
./gradlew assembleRelease -Pversion_name=3.0.0 publishRelease
build.gradle
def version_name = project.getProperty("version_name")
println "version name: "+version_name
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode version_code
versionName "${version_name}"
renderscriptTargetApi 23
renderscriptSupportModeEnabled true
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
...
}
But still nothing. Just to be clear the problem is not that I'm not getting the version_name or the wrong version_name in the build, in fact that println you see there prints the right version. Is just that I'm not getting anything at all in the Google play store (see image below).
This is not the issue of plugin or API. This is just how gradle works. Other answers indicating the problem are here or here.
Basically the problem is that gradle might create a JVM fork processes to complete the tasks. Therefore, when running publishRelease, which depends on
assembleRelease, separate process might be created to finish assembling before publishing. And you pass system property to publish taksand not assemble task.
The solution might be to run two tasks simultaneously, passing argument to appropriate one:
./gradlew assembleRelease -Dversion_name=3.0.0 publishRelease
Or set project property instead of system property as described here

Android build flavor sqlite database

I'd like to create a demo from my application, so I tried to build another flavor, but if I try to run it, I get this exception:
attempt to write a readonly database (code 1032)
Original Gradle
defaultConfig {
minSdkVersion 9
targetSdkVersion 24
applicationId 'com.myapp.foo'
versionCode 518
versionName '4.3.2'
}
and this is my gradle with the two flavors
defaultConfig {
minSdkVersion 9
targetSdkVersion 24
}
productFlavors {
baz {
applicationId 'com.myapp.baz'
versionCode 1
versionName '1.0.0'
}
foo {
applicationId 'com.myapp.foo'
versionCode 518
versionName '4.3.2'
}
}
Are you sure you have your flavor specific source segmented correctly so that you only have one SQLiteOpenHelper? Meaning you have one under src/baz/java and one under src/foo/java but not one under src/main/java? Or just a single one under src/main/java?
In your AndroidManifest.xml provider section, it should be like the below one.
<provider
android:name="com.zoho.invoice.provider.ZInvoiceProvider"
android:authorities="${applicationId}"
android:writePermission="${applicationId}.permission.WRITE_SCHEDULE" />
So that the appropriate application id will be replaced while build process.
Also, in your whole project where ever, you use your application id, should be replace with the placeholder.
In your Java file, it can be accessed as
BuildConfig.APPLICATION_ID

Setting ApplicationID for every build variant

I need to set my application ID for a build variant.
I have a defaultConfig in my build.gradle, which sets the applicationId
defaultConfig {
applicationId "mycompany.mainappname"
minSdkVersion 12
Now I need to set the application ID to "mycompany.mainappname_fullversion". (no dot between mainappname and _fullversion)
I need this, because I have published my fullversion to googleplay 4 years ago with this name.
How can I do this ?
I tried to use the applicationIdSuffix syntax in my buildTypes Section to add the suffix, but it also adds me an "." befor the suffix, which is in my case wrong -> "mycompany.mainappname_fullversion._fullversion"
buildTypes {
full {
applicationIdSuffix '_fullversion'
I also tried to set the applicationID with applicationId "mycompany.mainappname_fullversion" in my build section, but i throws errors.
How can I simply set the applicationID to ""mycompany.mainappname_fullversion" in a build ?
Can someone help ?
Place a separate manifest in each build variant's directory under src.
Try removing applicationId from defaultConfig and add applicationId in each of buildTypes
buildTypes {
full {
applicationId 'mycompany.mainappname_fullversion'

Android Studio 1.0 and error "Library projects cannot set applicationId"

After updating Android Studio to 1.0, I see this error:
Error: Library projects cannot set applicationId. applicationId is set
to 'com.super.app' in default config.
I updated the Gradle plugin as suggested but I did not understand how to fix this.
Based on this info:
ApplicationId in Library Projects
You cannot use applicationId to customize the package of a library project. The package name has to be fixed in library projects (and specified as packageName in the manifest). The Gradle plugin did not enforce this restriction earlier.
Removing applicationId variable from the library's build.gradle file should resolve the issue.
Thanks to Joel for his correct answer: I need to remove only 1 line from te .gradle file:
defaultConfig {
applicationId "com.super.app" <---- remove this line
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
becomes
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.super.app">
...
This is the right solution if you don't need to rename the package name of your app. To rename it you need to use "flavours":
android {
...
productFlavors {
flavor1 {
applicationId 'com.super.superapp'
}
}
Libraries can't set applicationId and if you are working in a multi-module project and picking up flavors from a separate file , none of the above answers will work. For a modularized app, you need the following steps -
Create a flavors.gradle file in project root directory
ext.flavorConfig = { // 1
flavorDimensions "pricing"
productFlavors {
free {
dimension "pricing"
ext.myApplicationIdSuffix = '.free' // 2
}
paid {
dimension "pricing"
ext.myApplicationIdSuffix = '.paid'
}
}
productFlavors.all { flavor -> // 3
if (flavor.hasProperty('myApplicationIdSuffix') && isApplicationProject()) {
flavor.applicationIdSuffix = flavor.myApplicationIdSuffix
}
}
}
def isApplicationProject() { // 4
return project.android.class.simpleName.startsWith('BaseAppModuleExtension')
}
In 1 we export a closure so that we can use it in our modules’ build.gradle files.
In 2 we define a custom myApplicationIdSuffix property. We cannot simply have applicationIdSuffix as it is not possible to use it in library modules (build would fail if you did).
In 3 we iterate over created flavors and set applicationIdSuffix if we detect that it’s an application module only.
4 is a way to check where this closure is being used.
All that’s left is to use this closure in our modules’ build.gradle files. E.g. in application module this would look like this:
apply plugin: 'com.android.application'
apply from: "${rootProject.projectDir}/flavors.gradle"
android {
// other config...
with flavorConfig
}
If this isn't clear, you can check out this article for better understanding.
Just incase it helps some one :
When i imported an eclipse project into android studio,i got an error ::
"Error:Application and test application id cannot be the same"
Strange though,but i looked into the build.gradle and found the two placeholders,one for the application and other for testapplication.
I removed the testApplicationId from that as is suggested in this post and this helped me resolve the issue.
Note: This explaination is not related to the errors posted in this question,but might help someone who is getting a similar error.
You cannot define applicationId for your lib.
But incase you want to use an identifier in your build file, which will give you, your library package name, you can define a variable for the module and then use the value as required.
eg : Library's build.gradle
apply plugin: 'com.android.library'
def libraryGroupId = 'com.google.example'
def libraryArtifactId = project.getName()
def libraryVersion = '1.1'
Also, you can use the value below as needed in your build file itself in lib.
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "$libraryVersion"
resValue "string", "Library", libraryGroupId"
}
}

Android - change app version name based on flavor

I want to change the app versionName to whatever is defined in the AndroidManifest file for the specific flavor I'm building.
So if I'm only building one of the 4 defined flavors I have, like:
gradle assembleFlavor1Debug
I was expecting Flavor1 to have the same version name as the one defined for its specific manifest (because of the merging of manifest files), but that's not happening.
How can I know, during build time, which specific flavor is being built?
Because if I know what flavor is being run,
I can extract the respective versionName from the manifest and set it on android.defaultConfig.versionName,
which solves my problem.
As of at least Android Studio 3.1.1 you can do this...
defaultConfig {
versionName "1.0.0"
}
flavorDimensions "dimen1", "dimen2"
productFlavors {
'flavor1' {
dimension "dimen1"
versionNameSuffix "-F1"
}
...
'flavorA' {
dimension "dimen2"
versionNameSuffix "-FA"
}
}
Then for variant flavor1FlavorA the versionName would be 1.0.0-F1-FA
https://developer.android.com/studio/build/build-variants#product-flavors
You can do this in this way
productFlavors
{
test
{
applicationId 'com.example.test'
versionName '1.0.0.test'
versionCode 1
}
product
{
applicationId 'com.example.product'
versionName '1.0.0.product'
versionCode 1
}
}

Categories

Resources