How to rename your template Flutter app for Android

When you create a new Flutter app using the command "Flutter create", it generates a template app. It is a great place to start, but you often want to change the name from that is generated. This article explains how and also an error that I bumped into.

Estimated read time : 6 minutes

Jump to

Key takeaways

  • Files you need to update to rename a Flutter app for Android
  • An error causing the app not to start in my emulator and how I fixed it
  • How to easily create a new template app using “flutter create app”

Background and purpose

I’m creating a POC for a new app that we are building and during that process you want to create boilerplate apps to test out specific and isolated scenarios. However, that is not what this article is about. This article will briefly describe how to quickly generate a boilerplate app using Flutter's built in template and how to change name of the app.

How to create a template app with Flutter

Once you have developed a couple of apps I guess you setup your own templates, but if you just want to test out new concepts Flutter has a built in command to setup a completely fresh app.

Just open Visual Studio Code (or the IDE you prefer) and a terminal in that folder where you want to create your new project. In the terminal window (this assumes you have already installed the flutter SDK).

flutter create app

If you want to read all commands you can use the -h flag to get more information.

flutter -h

Once that is done the new app is generate.

This is fantastic and will create the simple “Flutter demo”-app.

So that is all good, beside the fact that this also defines the name of the app to be “”, which I want to change.

How to change the name of a flutter app

First of a tip if you want to simplify this a bit, check out this extension:

There are a couple of places where you have to set the new name. First off, you should look for the file AndroidManifest.xml. There should be three of them:

  • Android
    • App
      • Src
        • Debug
          • here
        • Main
          • here (this is the primary that you see in the image below)
        • Profile
          • here

After you have changed the package name in that file you have to update the app>bradle.config file. The setting to change is under “defaultconfig”:

defaultConfig {
        // TODO: Specify your own unique Application ID (<>).
        applicationId ""
        // You can update the following values to match your application needs.
        // For more information, see: <>.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

That should do it.

Error when running the app

However I got an error when trying to reload the app after renaming it as above.

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{YOUR APP/YOUR APP Namespace.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "App Namespace.MainActivity" on path:

What I found was that a file called MainActivity.kt under Kotlin is generated.

In that file it references the namespace of the app and if that is not in sync with the name changes, that will crate the error seen below.

E/AndroidRuntime(11055): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{}: java.lang.ClassNotFoundException: Didn't find class "" on path: DexPathList[[zip file "/data/app/~~HoQV073_0Wk2u3mbf64q0Q==/"],nativeLibraryDirectories=[/data/app/~~HoQV073_0Wk2u3mbf64q0Q==/, /data/app/~~HoQV073_0Wk2u3mbf64q0Q==/!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at$H.handleMessage(
E/AndroidRuntime(11055):        at android.os.Handler.dispatchMessage(
E/AndroidRuntime(11055):        at android.os.Looper.loop(
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11055):        at$
E/AndroidRuntime(11055):        at
E/AndroidRuntime(11055): Caused by: java.lang.ClassNotFoundException: Didn't find class "" on path: DexPathList[[zip file 
"/data/app/~~HoQV073_0Wk2u3mbf64q0Q==/"],nativeLibraryDirectories=[/data/app/~~HoQV073_0Wk2u3mbf64q0Q==/, /data/app/~~HoQV073_0Wk2u3mbf64q0Q==/!/lib/x86, /system/lib, /system_ext/lib]]

Hope that helps.

Main image: Photo by Daniel Romero on Unsplash