Publishing multiple apps under same package - Android - android

I have an application that supports different domains. My code is developed under the package: com.example. I would like to publish multiple application under different packages like:
com.example.domain1, com.example.domain2, etc.
In the manifest I define:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.domain1"
....
and for domain2:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.domain2"
The problem I am facing is that once I change the base package name from domain1 to domain2 I need to rename all my packages in the src folder as well as layouts. What I am looking for is to keep the same base packaging com.example and distribute the different apps under its sub-domains.
Is there a better way?
Clarification:
When changing the package name, the resources file changes from com.example.R to com.example.domain2.R. This means that I have to go into all src java classes and layouts etc. and update the generated R file location. That is not handy.

I ended up marking my main project as a library and then creating a project for each domain and linking to the library.
No need to play around with the manifest or the R.java file.
Thanks to #Tenfour04 for pointing me in the right direction!

In your manifest, each Activity, Service, Provider and Receiver has a name attribute. By default they use a shortcut like ".MainActivity" The leading . is a shortcut for the package name at the top level of the manifest.
So if you don't want to rename all those packages in the src folder, just type out explicit names for the Activities, Services, Providers, and Receivers in your manifest, for example, android:name="com.example.sharedmultiprojectdomainname.MainActivity".

If you are using Gradle as your build system, you might want to incorporate build variants into your build, which will solve package problems. More on this can be found in this Google I/O speech
Hope this helps.

Related

What's the final package name of an activty after gradle merges manifests in a app+library project?

I have a project that is formed by a project and a library project. Both of them have their own manifest.
The library project has all the acitivities definitions (and practically all the code). The app project has a manifest where only an Application class is defined. (If you ask why i have this structure is because i have a common library and i create multiple app projects to change themes and api calls)
My question is, when i have to define my initial activity class name in platforms, i.e Facebook, should i use my library project package name as it is defined in its manifest? or gradle merges it with my app project package name?
Example:
com.app.finalproject is my application package name.
com.commonlibrary.ui.SplashActivity is my common package name of my initial activity and it is defined in my common library project manifest.
So, after gradle merges the two manifest what is the package name of my SplashActivity ? is it still com.commonlibrary.ui.SplashActivity o is it something like com.app.finalproject.ui.SplashActivity ?
Thanks in advance.
Activities do not have a package name, strictly speaking.
The Java class that implements an activity will be in a Java package. That package is denoted by the package line at the top of the class file, along with the directory in which the Java class resides. None of that is affected by the manifest merger process.
Sometimes, you need a full ComponentName of an activity or other component. In that case, the package portion of the ComponentName will be the application ID. The Java class portion of the ComponentName will still use its regular Java package.
Using your example, if I am understanding it correctly, the activity is still com.commonlibrary.ui.SplashActivity. The ComponentName for that activity would be com.app.finalproject/com.commonlibrary.ui.SplashActivity.

Google play says: "You need to use a different package name" - why?

I have already published an app called com.mycompany.mygame on google play.
I then decided to publish an ad free version of it. I did not change the package name in eclipse because I noticed that in the "export" process you have the opportunity to have the final apk set as anything you like. So I set it there as com.mycompany.mygameaf - note the additional "af" on the end. But then when tried to upload it to the market, google said:
You need to use a different package name because "com.mycompany.mygame" is already used by one of your other applications
So now I'm confused. Is the complaint because I'm not allowed to have an apk that is a name which is and extension of a previous app? Or does the final apk somehow have knowledge of what the original name was?
What is the easiest way to resolve this?
Apart from correcting app name in the Manifest I also had to change applicationId in the app's gradle.build file.
defaultConfig {
applicationId "com.example.changednameofmyapp"
...
}
Also, if you're using ProGuard, do not forget to change appropriate rules in your proguard-rules.pro
Just search the old package name in the whole project and change it.
Regardless of the name of the .apk file, the package name of the Application contents inside it must be unique.
You can use refactor-rename to change this, though make sure that the change penetrates to the manifest file, proguard configuration, etc.
The name of the APK doesn't matter, its the package name within the AndroidManifest file that counts.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.yourapp"
There can only be one app on the market with that package name so in order to publish your ad free version you would have to change the package name in the manifest file, e.g. add the af onto the end of the package name within your manifest.
As mentioned in other answers, you're development would be simpler if you put all the shared code and assets a common library project that is a dependency of your paid and free versions.
You may also wish to play with the new Gradle build system (in Android Studio) which allows you to dynamically set things like the package name at runtime. It also allows you to switch resources during build time, which is extremely convenient; You could have a boolean resource that represents whether the current app is the paid version. This allows you to enable/disable app features based on a check to that value.
The filename of the APK is irrelevant, the package name of your app is used as a unique identifier - it is in the root element in the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.packagename"
android:versionCode="1"
android:versionName="1.0" >
When you initially create your project in Eclipse it creates an actual package structure which matches this package name for you to put your source files in.
You can actually chnage your package name by modifiying this manifest value and you can just keep the folder/package structure as is - it does not need to match your actual application package name.
Alternatively, right click your project in Eclipse, go to "Android Tools" and then select "Rename Application Package"
After you do this you should be able to submit your binary
The package name in the manifest is used to identify the application within Android and within Google Play. So different apps need different names.
The easiest workaround might be to just create a new package, with no code in it, and use that as the app's package name in the manifest.
What I've done to solve my many-apps-from-one-codebase problem is put all the apps' code in a library project, and then I have several app projects that use that library. The app projects contain no code, just a manifest and custom resources.

Missing translation errors in Android

When exporting a signed android package I get the following error:
app_name to translated in es,he,iw
No where in my app I have defined these three languages. I am not able to understand how lint is coming up with these languages. Is there any configuration that I might have updated my mistake?
I know that I can turn off this lint error by going to Window > Preferences > Android > Lint Error Checking > MissingTranslation. But that is not what I want to do. I have no plans to translate my app to these languages, then from where are these errors showing up.
Is there any file where I can define that my application uses only one locale?
I found the answer to my question. I am using FacebookSDK as a library function which has the folders values-es, values-he, values-iw which the android-lint is also expecting in my project.
To fix my issues I have removed these folders from FacebookSDK and recompiled my application.
However I do not think android lint should be flagging these as errors as they are not being used in my project, but that would be a different discussion.
To generalize the answer for the benefit of other developers stumbling here:
Check if you have created any values- folders, eg values-es, values-he, values-iw. If yes and you do not plan to use them remove the folders.
If you have not created the values- folders check if you these folders are present in any library project that you have referenced. If not needed in the library project remove them and recompile.
Note: If you remove folders from library project make sure to back them up as you may require them later.
you missed to mention the app_name in the all string.xml files , you may mention in only on one values file , but not in other two lang values . please check it.
values-en
values-he
values-iw
you have to mention in above three folders also..
Check your project, whether you have these folders in res/: values-es, values-he, values-iw.
If you donot want to support these languages, delete them.
If you want to support some languages, each strings.xml need have app_name item.

android eclipse custom version of same project

I want to try 2 difference version of the same app on my tablet.
So imported both project in eclipse with different project name.
I changed the name of the app in the manifest, I changed the icon to be able to recognize them on my desktop ...
I just can't get both on the phone at the same time. I can execute them both, but installing one is gonna erase the other.
I guess its the change I'm looking for is in the manifest.xml, still I can't find it.
You have to change your package name. A Package name must be unique for every app.
From the official doc
Package Name is the package namespace for your app (following the same
rules as packages in the Java programming language). Your package name
must be unique across all packages installed on the Android system.
For this reason, it's generally best if you use a name that begins
with the reverse domain name of your organization or publisher entity.
In Eclipse, in the Package Explorer select the com.xxxx.yyyy in the src/ directory of the project whose manifest you changed. Right click -> Refactor -> Rename. Enter a new package name, e.g. com.abc.test
Then, in the manifest XML, also replace all instances of "com.xxxx.yyyy" with the new "com.abc.test" package name.

Android: Including multiple Java Packages to Manifest

The app I am developing has many activities organized into seven java packages. Originally I wrote all the coding and stuff for each group of activities in a java package as different projects.
Now I'm at the point where I want to put all the packages together into one project. When I add a new package to the src folder, I get an error for all my R.id.* values ("R cannot be resolved").
My instinct tells me that there is something fancy I have to put in the project manifest, but I can't find any resource online to tell me how.
(Note: I have read this and this and I still couldn't figure out how to add additional packages to my project.)
Make sure that the import statement at the top of the Activity references the correct R file. Each project has its own R file, so if you copy an Activity from one project to another it will still be trying to reference the R file from the old project.
You do not need any explicit inclusion of different packages in the manifest. To include activities from two different packages, say:
com.example.package1.Activity1
com.example.package2.Activity2
you can do the following:
<manifest package="com.example" . . . >
<application . . .>
<activity android:name=".package1.Activity1" . . . />
<activity android:name=".package2.Activity2" . . . />
</application>
</manifest>
Android automatically creates the class named "R" in the package declared in your App's manifest. When all of your classes are inside that package, you'll never have to explicitly import "R". However, if you have classes in other packages, they won't see it by default and you will have to include
import <app-package>.R;
or
import <app-package>.*;
(substituting the actual name for <app-package> of course).
If you include library projects in your App, then they can reference their own "R" classes, which will be generated within their home packages. If you have several independent activities which need to be bundled together into one final App, you should seriously consider using library projects instead of manually merging things. It could make life much easier for you.
The problem may persist even if we change the manifest file.
To avoid it, we must add an import com.example.R; in all our classes.
Example:
MainActivity.java in package2
package com.example.package2.Activity2
import com.example.R;
TestActivity.java in package1
package com.example.package1.Activity1
import com.example.R;
Check that the layout -> main.xml file is correct and includes the android:id="#+id/whateverIdHasCausedYouTheError"
The R.java file will then be updated to include the id.. and bam, your error should disappear.
I am using APK Builder and all xml resources are declared in an auto generated java file by aapt. Its package name is you guess, the android manifest package name.
Then it dawned on me that xml files dont have package names. All xml files are just xml files. Then aapt generates an R class with all XML resources in one R class. The package name of this class is the one in the manifest.
So either import package-name.R or just use one package for your entire project.

Categories

Resources