【问题标题】:Flutter, how to have release and debug app on the same device?Flutter,如何在同一设备上发布和调试应用程序?
【发布时间】:2020-09-19 08:19:15
【问题描述】:

我正在开发一个可以从 Google Play 下载的应用程序(目前只有 android)。 我已经在手机上安装了发布的应用程序。但是,每当我使用 android studio 在我的设备上启动调试时,它都会删除已发布的版本。 我想要的是在我的设备上同时拥有两个应用程序,例如 "App""App_debug"

如何设置我的项目,使调试和发布应用之间不存在冲突?

谢谢。

【问题讨论】:

    标签: android flutter dart


    【解决方案1】:

    我设法找到了解决方案(仅适用于 android)。

    为了不删除从 Google Play 下载的“已发布应用”,我在文件 android/app/build.gradle 中添加了这些行:

    android {
        buildTypes {
            // ------ Start Changes -----
            debug {
                applicationIdSuffix ".debug"
            }
            // ----- End Changes -----
        }
    }
    

    这样,对于发布应用程序包将是 com.example.app,对于我的调试应用程序,包将是 com.example.app.debug,并且不再存在冲突。


    不过,我还想要一个不同的应用名称,以便区分这两个应用。 为此,我关注了this comment

    android/app/src/main/AndroidManifest.xml文件中我做了这个修改:

    <manifest ...>
        <application
            // before : android:label="App"
            android:label="@string/app_name"    // <- After my changes
        >
        </application>
    </manifest>
    

    然后为发布应用设置名称,创建或修改文件android/app/src/main/res/values/string.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">App</string>
    </resources>
    

    对于调试版本,创建或修改文件android/app/src/debug/res/values/string.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">App Debug</string>
    </resources>
    

    【讨论】:

    • 不幸的是,这不起作用[]任务':app:processDebugGoogleServices'的执行失败。 [ ] > 找不到与包名称“com.myapp.debug”匹配的客户端
    【解决方案2】:

    您要查找的内容称为flavors。您可以在flutter official docs 中查看有关它的更多信息或查看以下软件包:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多