Status Update
Comments
jv...@google.com <jv...@google.com> #2
uc...@google.com <uc...@google.com>
pa...@google.com <pa...@google.com> #3
qu...@google.com <qu...@google.com> #4
so...@google.com <so...@google.com> #5
MacOs Sierra 10.12.6
Android Studio 2.3.3
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
qu...@google.com <qu...@google.com>
qu...@google.com <qu...@google.com> #6
qu...@google.com <qu...@google.com> #7
I am not sure what is the desired behaviour. applicationPackage
is usually set with AndroidModuleModel.getApplicationId()
and it returns "one.name.debug"
in this case. Is this correct behaviour? If not, shall this method return something else or should we call something else instead?
We use applicationPackage
in a few places, for example we add "import ${applicationPackage}.R;"
to the main fragment code file. Is seems that using applicationPackage
is correct here?
Also, sometimes we use applicationPackage
when we have no known package, i.e. we create something in a module, not inside some specific package. Usually it is used for package name suggestion but in some cases we use suggested package implicitly, without rendering it in UI. Is it an okay thing to do or should we use some other default?
sm...@gmail.com <sm...@gmail.com> #8
So let us say the the default package is one.name
. This is the name we are shipping to production with.
The compiler generates the R file with the name of one.name.R
. This makes sense since that is the correct name for compilation as it needs to match and be consistent regardless of if an applicationIdSuffix was specified so that developers don't have to change the import headers for each variant.
The bug is the template is filling in with import one.name.debug.R
which doesn't exist if an applicationIdSuffix = ".debug"
was specified.
I had long given up on this bug and just not use templates or grumble about removing the incorrect ".debug" addition to the import path when I do. I originally raised this
sa...@google.com <sa...@google.com>
so...@google.com <so...@google.com> #9
Please use org.jetbrains.android.dom.manifest.AndroidManifestUtils.getPackageName
which returns the so-called resource package name (the Java package name of the R
class) and it does not depend on the currently selected build variant.
applicationId
also called (in APKs and Android OS it is also called packageName
) is not the same as the resource package name. It is used to as an ID when the app is deployed and might differ from the R
class package name.
so...@google.com <so...@google.com> #10
Unfortunately the JavaDocs to this and related methods are not helpful and contradict what I said above. We need to fix them and I'm adding tests to avoid any future ambiguity.
The method itself always returns the package name from the main manifest which is the R
class Java package name and I'm adding a test to ensure this behaviour and avoid any ambiguity.
Description
Creating a new template results in using the gradle override to set the package name of class created.
As overriding applicationId in gradle is needed for certain scenarios like using different applicationIds for release and debug to allow oauth authentication flow with different signing keys, this leads to annoying behavior where the template package name is not what you want.
Repro steps:
--------------------
1) create a new project
2) set the applicationId in the wizard to "
3) open the app/build.gradle file
4) under android.buildTypes, add:
debug {
applicationIdSuffix ".debug"
}
5) gradle sync the project
6) File, new, fragment, Fragment (Blank)
7) click through the wizard
results:
-----------
fragment java/kt file created in the one.name.debug package
expected:
---------------
fragment java/kt file created in the