skip to Main Content

When creating a flutter app with Visual Studio Code and trying to upload it to the Google Play Store via the Google Play Store Console, I received the following error:

"The use of "com.example" is subject to restrictions. Please use a different package name"

This relates to the default name used that includes the example part. There are many guides online on the relevance of the package name, naming convention, and how to update the name in Android Studio.

I was completely lost in how to update it in Android Visual Studio Code…

2

Answers


  1. Chosen as BEST ANSWER

    Some online guides propose to only change the two occurrences of "com.example" in the build.gradle, which is located in apppath/android/app/

    from

    android {
    namespace "com.example.XXX"
    [...]
    defaultConfig {
    applicationId "com.example.XXX"
    

    to

    android {
    namespace "com.newname.XXX"
    [...]
    defaultConfig {
    applicationId "com.newname.XXX"
    

    However: While, after 1) saving, 2) flutter clean, 3) flutter build appbundle, the new version might actually be accepted by the Play Store, there might be issues with starting the app, since the package name has not been updated across all occurrences in the code. Under Visual Studio Code, I was not able to use refactor features, that seem to be able to help out with fully replacing these in Android Studio.

    However, you can replace all occurrence via edit -> find in files -> with input "com.example". Once replacing "example" by "newname" for all occurrences, the app was able to both function correctly and be uploaded to Play Store.

    Hope this helps some people struggling with the same problem :)


  2. In this cause you can change your configuration in your build.gradle in app level.

    When you went to your build.gradle in app level you can see applicationId in deaultConfig section like bellow code.

       defaultConfig {
            
            // this is your defult applicationId
            applicationId "com.example.testing"
            minSdkVersion flutter.minSdkVersion
            targetSdkVersion flutter.targetSdkVersion
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            multiDexEnabled true
        }
    

    so when we want to upload our app into playstore we should change applicationId like bellow.

    applicationId "com.boss.testing"
    

    because it should be unique. you can findout more details refer flutter documentation using this link. look at updated code,

       defaultConfig {
            
            // this is your new applicationId
            applicationId "com.boss.testing"
            minSdkVersion flutter.minSdkVersion
            targetSdkVersion flutter.targetSdkVersion
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            multiDexEnabled true
        }
    

    and rebuild your project again now you can avoid this issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search