Android Studio - Change applicationId in build.gradle file - android

How can I change the applicationId field of my build.gradle file?
defaultConfig {
applicationId "com.oldname.appname"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
I've already renamed the package structure to com.newname.appname and all the imports and things like that have updated, but applicationId hasn't. I can't refactor it and just trying to type in a new name brings up a ton of errors where Android Studio will tell me my main FragmantActivity "is not applicable to android.app.Activity" and so on.
Any idea what to do? Thanks in advance.

You can create different flavours for one application in Gradle file. This will increase the code reusability.
An example for an application with Paid and Free flavors:
productFlavors {
paid {
applicationId "com.oldname.appname.paid"
}
free {
applicationId "com.oldname.appname.free"
}
}
So these two flavours will act as two products. You can upload it to play store as different applications.
You can also get four build variant for this two flavours.
com.oldname.appname.free- debug
com.oldname.appname.free- release
com.oldname.appname.paid- debug
com.oldname.appname.paid- release

Apart from the usual java files and manifest that had to be renamed I had to also change the settings under Project Structure:
SO I went to File > Project Structure > Modules/app > Flavours
I then changed the Application ID and all worked great.
Hope this helps for other MAC users like myself. (Did not test on Windows)

Related

package name change but not working in gradle

package com.abhimathgame.shubham.mindsharp;
In build.gradle in manually change the package name
defaultConfig {
applicationId "com.abhimathgame.shubham.mindsharp"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
And after that i sync the gradle but it return error and whrn is use
applicationId "com.example.shubham.mindsharp"
it ok but not publish on Playstore Error Image for more help
Try first of all to update google service to the most recent version.
Also do you use flavors?
Also could be that you re using New Relic as indicated in this post? It is referring to this tutorial where is explained exactly the nature of the issue:
the google_services.json must reside in the root of your :app module
and not within a buildType/productVariant folder, so Gradle cannot
handle this automatically for you via folder placement.
Make sure your package name is same at all the places. Also if you have added google-services.json file from firebase in your project make sure the packagename added there is correct.
Hope this is helpful.

You need to use a different version code for your APK because you already have one with version code 1

i know this has been ask here
The correct answer is to change the version does not solve my problem
id did added this two lines in my manifest
android:versionCode="2"
android:versionName="2.01"
but then when i clean and build using android studio the generate the apk again then upload the same error happend ..
Note: I did check that it is the correct file that i try to upload in the developer console
In the build.gradle file check if you have versionCode like
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
because if you have mentioned versionCode in build.gradle file then it will overwrite the values in manifest file. Please make sure if you have mentioned version code here then you have updated here also.
Change it in the build.gradle file of your app module in Android Studio.
Remove those from your manifest. Go to File>Project Structure> And either flavors or build types (don't remember and don't have my pc on me). Set the version name and version code from there.

How do I set configuration using Gradle for build flavors

Existing system (Maven)
I have an Android project which has two modules: app and api.
Currently, I use Maven to build it, and I have a configuration.properties in the app resources directory which has properties in it such as exampleProperty=${property}
I use the command line for my various builds like so mvn clean install -Dproperty=customString, and this swaps out the correct property so that it is exampleProperty=customString.
This property is read from by both app and api modules - and works fine.
New system (Gradle)
The Question: Can I use defaultConfig to set a property in my configuration.properties file?
I'm trying to use the defaultConfig (and eventually productFlavors) to create a setup where the build.gradle swaps out the properties instead of using the command line.
I've tried a number of ways to make changes to the gradle.properties file from the defaultConfig closure in the build.gradle file like so:
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
applicationId "com.example.editconfigproperties"
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
System.setProperty('exampleProperty', 'customString')
project.properties['exampleProperty']='customString'
extensions.add('exampleProperty', 'customString')
ext.exampleProperty = 'customString' // This one seems to work
}
}
I think the last one adds it to the gradle.properties file, but I can't figure out how to make the configuration.properties file read from it (or if that's even possible). I tried setting exampleProperty=#exampleProperty# in the `configuration.properties' file, but to no avail.

Android Studio 0.6.1 & Facebook SDK 3.15.0 famous error. how solve?

I'm trying to import Facebook SDK 3.15.0 to Android Studio 0.6.1.
I do follow Rani's explanation on using facebook sdk in android studio both for Android Studio earlier than 0.5.5 & the later one.
The error I get says something like this.
**Error:Execution failed for task ':app:processDebugResources'.
Error: A library uses the same package as this project: liquidcode.se.facebooktest
You can temporarily disable this error with android.enforceUniquePackageName=false
However, this is temporary and will be enforced in 1.0**
I also did include it in the setting.gradle & imported as module for the app.
I read now that many have the same problem, but how to fix it?
Thank you.
Delete the ApplicationId from your facebook sdk library build.gradle file.
It should end up looking something like this.
//Wrong
defaultConfig {
applicationId "com.bz.buktest"
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
//Right
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
Done. Your problem should be solved. Hope you got it.
I would start over, and add the project via the File -> Project Structure dialog. Mine worked with minimal additional effort after adding the sdk via the Project Structure dialog.
After adding via the Project Structure dialog, you need to change buildToolsVersion in Facebook's build.gradle file.
Also delete the component named FacetManager in Facebooks .iml file.
If you follow those three steps you should have Facebook's sdk properly integrated into your project.

How to change Android version and code version number?

How to change Android version and code version number Android Studio? I want to change apk file (app) on Google Play and I need to change Android version and code version number. I tried with this in AndroidManifest.xml file in Android Studio:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestsoftcorporation.circle.app"
android:versionCode="101"
android:versionName="2.0">
But it does not work. When I tried to publish it on Google Play it display that I must to change Android version name and code.
Go in the build.gradle and set the version code and name inside the defaultConfig element
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
The easiest way to set the version in Android Studio:
1. Press SHIFT+CTRL+ALT+S (or File -> Project Structure -> app)
Android Studio < 3.4:
Choose tab 'Flavors'
The last two fields are 'Version Code' and 'Version Name'
Android Studio >= 3.4:
Choose 'Modules' in the left panel.
Choose 'app' in middle panel.
Choose 'Default Config' tab in the right panel.
Scroll down to see and edit 'Version Code' and 'Version Name' fields.
You can define your versionName and versionCode in your module's build.gradle file like this :
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
.... //Other Configuration
}
Press Ctrl+Alt+Shift+S in android studio or go to File > Project Structure...
Select app on left side and select Flavors tab on right side on default config change version code, name and etc...
You can manage your application versioning wisely by using the Advanced Build Version Plugin for Gradle.
You just need to include the plugin in yout build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.moallemi.gradle.advanced-build-version:gradle-plugin:1.5.0'
}
}
apply plugin: 'org.moallemi.advanced-build-version'
And then you can use the versioning functions (and, obviously, customize them):
advancedVersioning {
nameOptions { }
codeOptions { }
outputOptions { }
}
def appVersionName = advancedVersioning.versionName
def appVersionCode = advancedVersioning.versionCode
For more information, take a look at the official documentation.
Open your build.gradle file and make sure you have versionCode and versionName inside defaultConfig element. If not, add them. Refer to this link for more details.
The official documentation on this is here.
The short answer is do it in Gradle not the manifest, Gradle overwrites the manifest.
The File | Project Structure | Modules | Default Config answer given above just updates Gradle via a UI rather than by directly editing XML.
The longer answer is:
If your app defines the app version directly in the element, the version values in the Gradle build file will override the settings in the manifest. Additionally, defining these settings in the Gradle build files allows you to specify different values for different versions of your app. For greater flexibility and to avoid potential overwriting when the manifest is merged, you should remove these attributes from the element and define your version settings in the Gradle build files instead.
Go in the build.gradle and set the version code and name inside the defaultConfig element
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
After updating the manifest file, instead of building your project, go to command line and reach the path ...bld\Debug\platforms\android. Run the command "ant release". Your new release.apk file will have a new version code.
I didn't get the other answers to work in Android Studio 1.4. But this worked:
click on your app name to the left below the main ribbon.
It will show a list of files.
Open AndroidManifest.xml and change the version code and version number there.
Android version and code version number change on Android Studio >= 3.6:
Two ways to achieve this:
Direct on the Android project by Open Flutter project and modify the file
local.properties
change the following values. Example:
flutter.buildMode=release
flutter.versionName=3.0.0
flutter.sdk=C\:\\src\\flutter
sdk.dir=C\:\\Users\\vgonza\\AppData\\Local\\Android\\sdk
flutter.versionCode=30
Open pubspec.yaml
Change the
version: 2.0.0+8
Meaning:
The version name is 2.0.0
The version code is 8
See example by Suragch in:
How to set build and version number of Flutter app
You can easily auto increase versionName and versionCode programmatically.
For Android add this to your gradle script and also create a file version.properties with VERSION_CODE=555
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['VERSION_CODE'].toInteger() + 1
versionProps['VERSION_CODE'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
applicationId "app.umanusorn.playground"
minSdkVersion 29
targetSdkVersion 30
versionCode code
versionName code.toString()

Categories

Resources