27

我在 Eclipse 中有两个 Android 项目。我从另一个项目中复制了一个项目,然后更改了应用程序名称(在 strings.xml 中)和项目名称(在 Eclipse 中)。

但是现在有一个问题:当在模拟器中运行其中一个应用程序时,另一个会丢失(可能被覆盖?)。所以我想我必须进行另一个设置,以便 Android 识别这两个应用程序是不同的?

谢谢!

4

11 回答 11

15

实际上,您需要在几个地方更改名称:

首先,如您所说,字符串的名称,即应用程序的可见名称。

其次,进入activity->src并右键单击包(com.example.whatever)并进行重构->重命名;

然后转到 manifest.xml: 并更改以下字段:

<manifest package="com.example.whatever" >

如果您使用本机代码 JNI,您还必须更改 c++ 函数的名称,这很麻烦:

Java_com_example_whatever_activity_function()
于 2013-11-29T11:06:34.197 回答
14

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
于 2017-01-10T16:43:42.537 回答
13

包名称(在 java 中)。

应用程序名称也在清单中,虽然我认为不需要是唯一的,但为了清楚起见,更改它仍然会很好。

于 2011-07-03T16:03:07.833 回答
10

For Android Studio users, you need to change your package name in AndroidManifest.xml and also in build.gradle file --> defaultConfig--> applicationId.

于 2014-12-17T17:30:37.347 回答
8

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.

于 2016-02-14T06:43:31.883 回答
4

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

于 2017-06-12T14:33:28.757 回答
3

I found that my rename wasn't working because I also needed to change the package name in google-services.json

于 2018-07-26T13:26:13.813 回答
3

My setup

  • Android Studio 3.5.3
  • Kotlin 1.3.x
  • macOS 10.14.6

Solution to Renaming appid

  • In Project Explorer, find app/java/com.company.app.
  • Right-click > Refactor > Rename, then select Rename Package.
  • Look down in the Refactoring Preview and make sure all package references are selected.
  • Click Do Refactor.

No need to hack around by hand.

于 2019-12-27T02:57:37.207 回答
2
  1. Change applicationId on app gradle.

  2. Change file_provider_authority in strings.xml

  3. 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.

于 2018-11-27T07:59:28.377 回答
1

应用程序的唯一标识符是包名。如果您更改软件包名称并重新安装应用程序,您最终将在手机上获得两份副本。

Eclipse 可以自动在代码的所有位置更改它。

只需在包资源管理器(项目树)上右键单击您的项目,然后转到 Android 工具->重命名应用程序包

瞧。

于 2014-08-06T11:24:16.637 回答
1

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".

于 2015-01-28T02:13:24.320 回答