我在 Eclipse 中有两个 Android 项目。我从另一个项目中复制了一个项目,然后更改了应用程序名称(在 strings.xml 中)和项目名称(在 Eclipse 中)。
但是现在有一个问题:当我在模拟器中运行其中一个应用程序时,另一个会丢失(可能被覆盖?)。所以我想我必须进行另一个设置,以便 Android 识别这两个应用程序是不同的?
谢谢!
我在 Eclipse 中有两个 Android 项目。我从另一个项目中复制了一个项目,然后更改了应用程序名称(在 strings.xml 中)和项目名称(在 Eclipse 中)。
但是现在有一个问题:当我在模拟器中运行其中一个应用程序时,另一个会丢失(可能被覆盖?)。所以我想我必须进行另一个设置,以便 Android 识别这两个应用程序是不同的?
谢谢!
实际上,您需要在几个地方更改名称:
首先,如您所说,字符串的名称,即应用程序的可见名称。
其次,进入activity->src并右键单击包(com.example.whatever)并进行重构->重命名;
然后转到 manifest.xml: 并更改以下字段:
<manifest package="com.example.whatever" >
如果您使用本机代码 JNI,您还必须更改 c++ 函数的名称,这很麻烦:
Java_com_example_whatever_activity_function()
For those who aren't using Android Studio and want to do it manually (e.g. if you're using React Native), I just recently went through this and had to change it in the following files:
index.android.js
android/settings.gradle
android/app/build.gradle
android/app/src/main/AndroidManifest.xml
android/app/src/main/java/com/<app id>/MainActivity.java
android/app/src/main/java/com/<app id>/MainApplication.java
包名称(在 java 中)。
应用程序名称也在清单中,虽然我认为不需要是唯一的,但为了清楚起见,更改它仍然会很好。
For Android Studio users, you need to change your package name in AndroidManifest.xml and also in build.gradle file --> defaultConfig--> applicationId.
The most simple way I have found to accomplish this task is to utilize Product Flavor in .gradle
productFlavors {
MainApp {
applicationId = "com.company.app"
}
NewAppFlavor {
applicationId = "com.company.newapp"
}
}
buildTypes {
debug {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + getDateAsMillis() + "L)"
applicationIdSuffix ".debug"
}
}
You then specify package name in AndroidManifest.xml as
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company"
android:versionCode="1"
android:versionName="0.1.1" >
Upon release configuration, Android Studio (1.5.1 as of this writing) will ask which flavor to build.
Debug configuration is a little less intuitive, you must hover the cursor over the bottom left corner of the screen, select "Build Variants" and select which flavor your debug configuration will deploy when you press the play button.
if you are using Android studio then
Your project identifier is in your build.gradle
file just change the field applicationId "com.example.whatEver"
Hope it will work
I found that my rename wasn't working because I also needed to change the package name in google-services.json
My setup
app/java/com.company.app
.Refactor > Rename
, then select Rename Package
.Do Refactor
.No need to hack around by hand.
Change applicationId
on app gradle.
Change file_provider_authority in strings.xml
If you are using firebase then add new project on firebase and download the new google-services.json file and replace the old one with this.
Optionally change your app name as well.
应用程序的唯一标识符是包名。如果您更改软件包名称并重新安装应用程序,您最终将在手机上获得两份副本。
Eclipse 可以自动在代码的所有位置更改它。
只需在包资源管理器(项目树)上右键单击您的项目,然后转到 Android 工具->重命名应用程序包
瞧。
Select Android on the top left of the Project window. So, right click over your package name under Java folder and select "Refactor" -> Rename... Click in Rename Package Button. Type the name of the new package you want, mark all options then confirm.
When it shows the results, click on "Do Refactor".