Android uses the package name as the unique ID for the app.
Assuming the package name is com.oc.objective, the following needs to be modified.
Two Java files
- Android/app/src/main/java/com/project_name/mainactivity.java
- Android/app/src/main/java/com/project_name/mainapplication.java
修改第一行
package com.oc.objective;
Description file for Android
- Android/app/src/main/androidmanifest.xml
修改第二行,把package的至改为com.oc.objective
package="com.oc.objective"
Two pack Scripts 1. Android/app/buck
修改两个package的值package = ‘com.oc.objective‘
android_build_config( ... package = "com.oc.objective",)android_resource( ... package = "com.oc.objective", ...)
Android/app/build.gradle
修改applicationID
defaultConfig { applicationId "com.oc.objective" ...}
After the modification is complete, the command line enters the Android directory and performs ./gradlew clean
a clear cache (on Windows gradlew.bat
)
Cannot link
At this point it's almost done, and the APK with the correct package name can be packaged. However, in the development process, if the need for automatic link native module, will cause the command error cannot link success. It is recommended that Java files be placed in a directory matching the package name according to Java specifications.
Move two Java files into the newly created directory android/app/src/main/java/com/oc/objective/inside, you will be able to react-native link.
- Android/app/src/main/java/com/project_name/mainactivity.java
- Android/app/src/main/java/com/project_name/mainapplication.java
React-native Modifying the Android package name