Android: product flavor, applicationId (package name) and manifest - android

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

Related

Build Android App with Old Manifest Package Name

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.

Issue with different packageName used in debugger vs runtime

If the flavor used specifies the applicationId as being com.example.boo and the manifest packageName is com.example.foo.
If i attempt to debug an activity and do an evaluate expression with findViewById(R.id.sampleView) it will return that resource was not found, because the R class belongs to com.example.foo, if i do it like it.resources.getResourceName((it.contentView as ViewGroup).getChildAt(3).id) it shows that the name is com.example.boo:id/sampleView
I found in the official documentation a subnote mentioning this behaviour.
But nothing telling me how to actually debug, because all expressions using resources will return false negatives/positives, since it cannot find the resources in question.
How do i solve this issue?
In your app's build.gradle file in section defaultConfig make your applicationId not include parts which you are using as flavors. For Example: you appId 'com.example.foo' and then name your flavors 'flav1' and 'flav2'. In that case you will have appId the same as your packageName and there should not be such problems with R file.
Your application will consists of applicationId(com.example.foo)+flavorName(flav1) = com.example.foo.flav1

AndroidManifest file with different package name for china for different flavor.

I am releasing the build for china market and we all know that they don't support Playstore. Henceforth we have decided to release in china stores.
One of the china store has requirement to have the package name in manifest file
must contain the application name. But right now our Main manifest file package name does not contain the application name.
So we created new Manifest file for china flavor with only package name change but Android studio expects the User Permission and Activity declarations in this china manifest file.
Can we create the manifest with only package name changes? All the other permissions and declaration must e taken from Main Manifest file.
You should specify package name in gradle for each flavor. Use the applicationId parameter
buildTypes {
forChina {
applicationId my.domain.appName.chinasuffix
}
notForChina {
applicationId my.domain.appName.other
}
}

Manifest package and applicationID can differ from real java packages of the application?

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

(Cordova/Phonegap) Android splash screen not being shown using Android Studio builds

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

Categories

Resources