I'm practising Android Program with a book
and it says if the package name is same, android understand it's same app even if the project is different.
so, I changed it with Refactor.
and it also says if you want to change app package name too, then please change the application ID in build.gradle(Module:app)
what is the difference between Package name & App Package Name?(Maybe the name is wrong because I just translate it.)
Every Android app has a unique application ID that looks like a Java package name, such as com.example.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
android {
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
...
}
Although your project's package name matches the application ID by default, you can change it. However, if you want to change your package name, be aware that the package name (as defined by your project directory structure) should always match the package attribute in the AndroidManifest.xml file, as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
Related
I have an app uploaded to the play store. The package is: com.pathapp but then with gradle are generated two apk, com.path debug and release (without app). Now I want to integrate firebase, but I do not know what name of the app is what I have to put in firebase, if com.path or com.pathapp in order to have a well constructed google-services.json file.
If I change the original package of the directories from pathapp to path, there would be a problem?
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.00"
}
}
applicationId in the gradle is your package name.
So you need to add that in the firebase console.
In the above example, the package name is com.example. Likewise, check your gradle.
If you go to the Play Store you can see the package name of your current app. Use this, or you won't be able to upload in the store.
To see the package name is linked with your Firebase, open your project in Firebase and click on Settings, here you will see the package name of the app.
If is not the same:
-There, you can see an option to add a new app. Click the button and add a new app with your new package: com.pathapp
-Finally, you have to download the new google-services.json and add it in your project, deleting the old one if you still have it.
we know APK save data in /data/data/PackageName,if two different apk with same package name,will they cover other's data?(like sharepreference's data)
The Answer is No, Why? This is not possible, Play store will not let you to upload an apk with the same package,Package name at play store is important for many reasons, one of them is update detection, if you updated an application the first thing Google pay attention is the package name in order to know what is the current release version.
Somehow it will be happened by same developer at the DEVELOPMENT stage only then you can name your package whatever do you want.
As far as same package name is concerned it's not possible to have installed on same device it will be replaced.
But if we have different appliationId, yes another app can be installed on same device but in that case packageName will also be change.
Working Sample
Project 1
app/build.gradle
applicationId "com.test.sample"
Android Manifest
package="com.test.sample"
Result
When i print applicationId and package name, it was same:
applicationId: "com.test.sample"
package: "com.test.sample"
Project 2
I've added buildTypes/flavor but keeping applicationId and package name same, but in that case outpout of applicationId and package name will be changed.
build.gradle(app)
applicationId "com.test.sample"
buildTypes {
release {
applicationIdSuffix ".release"
}
debug {
applicationIdSuffix ".debug"
}
}
Android Manifest
package="com.test.sample"
Result
When i print applicationId and package name, it was different:
applicationId: "com.test.sample.debug"
package: "com.test.sample.debug"
So that is how two applications are installed due to change in buildType/flavors(pro/free).
And if you want to access sharedPreferences of each-other (assume free/pro version) than you need to create a ContentProvider to expose data you need and grant permissions to paid app.
What is the mean of applicationId in build.gradle. and what is the difference between package name in manifest file and applicationId in build.gradle.
What is the mean of applicationId in build.gradle
Every Android app has a unique application ID that looks like a Java package name, such as com.nilu.myapp. This ID uniquely identifies your app on the device and in Google Play Store. If you want to upload a new version of your app, the application ID (and the certificate you sign it with) must be the same as the original APK—if you change the application ID, Google Play Store treats the APK as a completely different app. So once you publish your app, you should never change the application ID.
Read more about applicationId
what is the difference between package name in manifest file and applicationId in build.gradle
package specified in AndroidManifest.xml identify one application installed on the device
Read more from this answer and this also Package Name Vs Application ID
applicationId in build.gradle will overwrite the manifest file's package value. And in build.gradle file you can use productFlavors to define different flavors, and each flavor can have different applicationId.
productFlavors {
free {
applicationId "com.myapp.free"
}
paid {
applicationId "com.myapp.pro"
}
}
i started working on a project on android studio , initially i didn't know if I would go to launch the app so i let the package name be the same as given by android studio by default ( it was com.example.abhishek.tv ) .
Now I'm done with the app and want to launch it but here I got stuck as I'm having my domain name as abhishekint.16m.com but i don't know to change the default package name given by android studio .
I have three problems here
I don't know to change the package name efficiently and SAFELY. I'm reluctant while changing the package name after reading some of the stackoverflow links as I was not clear with the answer and package name seems very sensible as it can ruin the whole project if not done properly .
My original domain name has numerics and I found after searching online that there is something abnormal with the numeric domain name .
One more thing , as I've this app which has some of the videos from youtube so in case if I choose to change the package name of my project then will I have to change the package name of the API_KEY that i got after fingerprinting while getting the youtube API .
Change in your app-level build.gradle file
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.abc.xyz" // change here
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
This will override package name that exist in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.xyz">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
EDIT
From the documentation about naming packages in Java:
In some cases, the internet domain name may not be a valid package
name. This can occur if the domain name contains a hyphen or other
special character, if the package name begins with a digit or other
character that is illegal to use as the beginning of a Java name
This means you can't use a digit as the first character of a package (or a class, interface or variable name, for that matter).
abhishekint.16m.com not allowed but you can use abhishekint.sixteenm.com.
apk upload failed to the google play market.
I am trying to upload the upgraded version of my app to the google play but I am keep getting the message -
Upload failed
You need to use a different version code for your APK because you already have one with version code 1.
Your APK needs to have the package name com.corntail.project.
There is still something that is looking for com.corntail.project and it is not being found.
UPDATE:
In my AndroidManifest.xml, the relevant code is -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.corntail.main"
android:versionCode="1"
android:versionName="1.0" >
If you're using Android Studio or building with gradle, edit your gradle script (build.gradle) to change your package name and version. These values overwrite your AndroidManifest.xml file.
For example:
defaultConfig {
applicationId "com.xyz.abc"
minSdkVersion 16
targetSdkVersion 19
versionCode 2
versionName "1.1"
}
You need to change your android:versionCode="1" to 2 on the AndroidManifest...
Things you have to keep in mind when updating your application on Google Play :
Change Version code +1 depending on the old value - if it's 1 , you have to change it to a bigger number.
Change your App Version Name to something bigger / different if it's string - if your old version is 1.0 - it should be 1.1 / 1.0.1 or whatever you like (it's always a better option t have some version name strategy, if it will contains the date update addded or the revision it depends on you).
And if you want to be able to update your app, don't change project package name! That's how android system knows that this application is different than that one. If you change your package name, it's now acting like a new app and you won't be able to update it from Google Play Store! To change your package name to com.corntail.project first you need to change it in manifest and after that in your project's main package and you need to keep track of your activities, if you declared them with package name too. For example :
if your MainActiivty was declared in manifest like :
com.corntail.main.MainActivity
you need to change it now to be like :
com.corntail.project.MainActivity.
You need to use a different version code for your APK because you
already have one with version code 1.
You must change your version code in your androidmanifest.xml
Every time you update your app change this variable in you XML file:
android:versionCode="1"
You are getting 2 errors.
The Version Code: you always need to set a higher number in the versionCode and always use an integer number. (don't use 1.1)
android:versionCode="1"
The package name: it has to match the same string that you used in the latest version that you upload. So instead of package="com.corntail.main" you should use:
package="com.corntail.project"
After modify the AndroidManifest.xml save it and then search in the folder src the package called "com.corntail.main", right click, Refactor > Rename, and the new name should match what you put in package (in this example you should call it: 'com.corntail.project') and you are done!
Good luck!
You have change version code in increasing order i.e. 1,2,3...so on as every time you uploaded. In every upload version code should have greater number than previous upload version code. You can change version code in APP Module Build.gradle file.
Image
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.xyz"
minSdkVersion 14
targetSdkVersion 24
versionCode 5
versionName "1.1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
If you build with gradlew, you should check the build.gradle file,
the applicationId will overwrite the package value in the AndroidManifest.xml
android {
defaultConfig {
applicationId "xxx.xxx.xxx"
}
}