When I build an Android app, there's an error message shown like this
Package 'grwe.android.package' from AndroidManifest.xml is not a valid Java package name as 'package' is a Java keyword
but, I've already had an app that was published on Google Play Store before with that manifest package name,
So, what should I do right now?
I built android app using EAS (Expo & React Native)
Your applicationId does not necessarly need to match the source code.
Keep your applicationId as the published one in your gradle build file.
// build.gradle.kts
defaultConfig {
applicationId = "grwe.android.package"
...
}
Organize your kotlin/java source code in package like grwe.android.packer or grwe.android.packager
package com.example.codes
class SomeActivity : AppCompatActivity() {
...
}
Android System will launch your activity like
androidApplicationId/fullQualifiedClassNameForActivity
grwe.android.package/com.example.codes.SomeActivity
grwe.android.package/net.example.OtherActivity
Hope, it helps.
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.
Let's analyze this situation:
Manifest package and application ID on gradle file: com.myweb.mysuperapppackagenamewithaso
Real java packages inside the sourcecode of my app:
com.mysourcecode.package1
com.mysourcecode.package2
with the MainActivity here:
com.mysourcecode.package1.MainActivity.java
Is this possible and safe? Manifest package and applicationID can differ from real java packages of the application?
Below given are the three things which we need to think about,
applicationId: BuildConfig.APPLICATION_ID
packageName: getApplicationContext().getPackageName()
Java package: BuildConfig.class.getPackage().toString()
getPackageName gives the same applicationId which is created at the final moment from the gradle file and it overrides the AndroidManifest package. The final AndroidManifest contains the same applicationId.The getPackageName is the same as the applicationId as the applicationId overrides the packageName in the AndroidManifest at the final moment.
But for the Java code, the package is same as the project structure. The package that is used in your source code to refer to your R class, and to resolve any relative activity, service registrations, continues to be called the package as defined in your manifest. So, the AndroidManifest should have the package same as Java package to resolve relative activity, service.
So, with the same java package, we can create any number of APKs with all unique applicationId.
Example : application flavors
Reference : Android Package Name Vs Application ID
I build a two apk from same source code . both have Different name,icon background .i changed only UI and app name tow app have same package,
my problem is I can't install this both app on same device .when I try to install facing error message .
How I can run this two application (build from same source just change name and icon) on same device .? what are the values I should change in application to run this app separately .?
Kindly Give me a hand with this
You need to change package name to make Android System detect your 2nd app as different from first. App name doesn't matter.
Use productFlavors in your build.gradle file.
android {
productFlavors {
dev {
applicationId "com.company.app.dev" // package name for dev flavor
}
beta {
applicationId "com.company.app.beta" // package name for beta
}
production {
applicationId "com.company.app" // package name for production
}
}
}
All your files can still be in your src/main dir. Flavor specific changes can be placed in src/beta etc.
you just have to change the name and the package name of your second instance of the application.
I have the following product flavors in module's build.gradle
productFlavors {
pro {
applicationId "com.icounttimer.android"
}
free {
applicationId "com.icounttimer.android.free"
}
}
The package structure of my app module is:
src/main/java/com/icounttimer/android/MainActivity.java
Building pro-debug.apk shows the splashscreen correctly. However, free-debug.apk does not show the splashscreen.
Changing the applicationId of 'free' flavor to 'com.icounttimer.android' resolves the issue. But when using a different applicationId, the splash screen won't be shown.
Environment:
CordovaLib: v3.6.3
Android Studio 1.0 RC4
What is the reason for this behaviour and how to resolve this issue?
The reason which I found is as follows:
Changing applicationId via build.gradle, changes the app's package name.
Note that it is different from the package structure of the app which remains unaltered during different build variants.
The app package structure, in this case, is unaltered: src/main/java/com/icounttimer/android/MainActivity.java
Diving through the code, I found out that the showSplashScreen() methods in CordovaActivity.java (part of CordovaLib) get the resources as follows:
this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName());
The third arguments for getIdentifier(...) method is the package name of app.
getClass().getPackage().getName()
gets the pkgName based on package structure which always returns 'com.icounttimer.android' no matter which build variant it is.
To fix this, replace both of its occurences in CordovaActivity.java with:
this.getPackageName() //returns the name of the application pkg which is the applicationId
So I have base Application class, DApp.
My flavor application classes just extend the DApp.
for example
package com.d.android;
public class App extends DApp {}
In my gradle script the following is setup for the flavor:
productFlavors {
d {
applicationId = "com.d.android"
}
}
In my manifest I've declared my app like that:
name = ".App"
For some reason gradle does not honor the different package name given by applicationId.
For now I just resolved it by defining AndroidManifest files for each flavor and declaring the full class name for the app file, but that seems wrong. That means that my package name is wrong.
Any ideas?
I think the problem is that you are not specifying a package name. You should always specify the package name in the root of your default android manifest file like this:
package="com.exmaple.app"
Please take a look at this explanation by the Google guys, hope it helps.
http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename
Good luck