When you change the applicationId and namespace and the app stops running, it's typically due to a misconfiguration in one or more places. Here are the steps to correctly update the applicationId and namespace for your Flutter project:
- Update applicationId in build.gradle Open the build.gradle file located at android/app/build.gradle and update the applicationId:
android {
...
defaultConfig {
applicationId "com.cotocus.wizbrand.application" // Change this to your new applicationId
minSdkVersion 21
targetSdkVersion 30
...
}
...
}
Update Package Name in Dart
The package name in Dart should not be directly modified in the pubspec.yaml file. Instead, ensure that all references to the old package name in your Dart code are updated to the new package name.Refactor Package Name in Java/Kotlin Files
If you have any Java or Kotlin files, you need to refactor the package name. For example, if your main activity is located at android/app/src/main/java/com/example/flutter_application_1/MainActivity.java, you need to move it to android/app/src/main/java/com/cotocus/wizbrand/publisher/MainActivity.java.
In Android Studio, you can do this by right-clicking on the com.example.flutter_application_1 package and selecting Refactor > Rename, then updating the package name to com.cotocus.wizbrand.application.
- Update Android Manifest Update the package attribute in the AndroidManifest.xml file located at android/app/src/main/AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cotocus.wizbrand.application"> <!-- Change this to your new package name -->
<application
android:label="wizbrand"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"/>
<meta-data
android:name="flutterEmbedding"
android:value="2"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
- Update Package Names in Java/Kotlin Files If you have Java/Kotlin files, update the package declaration at the top of each file. For example, in MainActivity.java:
package com.cotocus.wizbrand.application; // Update this line
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
// Your code here
}
- Clean and Rebuild Your Project After making these changes, clean and rebuild your project to ensure that everything is correctly configured:
flutter clean
flutter pub get
flutter build apk
Top comments (0)