简体   繁体   English

Android - 用于调试和发布模式的应用程序图标

[英]Android - app icon for debug and release mode

如果我们在清单中设置 android:debuggable=true 并且我们在 iOS 中设置 android:debuggable=false ,是否可以为应用程序设置单独的图标?

I'm a bit late the party, but anyway.我参加聚会有点晚了,但无论如何。 At the moment I'm posting this in '16, you actually can have different launch icon set simply putting them to respective directories, not sure how it was back in '13 though.目前我在 16 年发布此内容,实际上您可以设置不同的启动图标,只需将它们放在各自的目录中即可,但不确定 13 年的情况如何。 To achieve that you need to create debug/res directories under app/src and place your mipmap or drawable directories there.为此,您需要在app/src下创建debug/res目录并将 mipmap 或 drawable 目录放在那里。 So you'll have app/src/main/res/ and app/src/debug/res/ paths.所以你会有app/src/main/res/app/src/debug/res/路径。 Android will have higher priority for build-related resource directory - to main directory. Android 将具有更高优先级的构建相关资源目录 - 到目录。 Place your debug and release resources to the appropriate paths and you'll have what you want.将您的调试和发布资源放置到适当的路径,您将拥有您想要的。 Do all of above considering you have to use Gradle build system.考虑到您必须使用 Gradle 构建系统,请执行上述所有操作。

Here you can read more about stuff like that: http://tools.android.com/tech-docs/new-build-system/resource-merging在这里你可以阅读更多关于这样的东西: http : //tools.android.com/tech-docs/new-build-system/resource-merging

A bit late but I'll leave my solution for who is looking for the same answer.有点晚了,但我会为正在寻找相同答案的人留下我的解决方案。

On the build.gradle where the buildTypes are defined, I added a suffix for my debug_test build type to have a different apk installed on my device.在定义了buildTypesbuild.gradle上,我为 debug_test 构建类型添加了一个后缀,以便在我的设备上安装不同的 apk。

buildTypes {
    release {
        ...
    }
    debug_test {
        debuggable true
        applicationIdSuffix '.debug'
        ...
    }
}

After that, go to File > New > Android Resource Directory and create a new mipmap resource directory for your debug_test build type (as you can see on Source set):之后,转到 File > New > Android Resource Directory 并为您的 debug_test 构建类型创建一个新的 mipmap 资源目录(如您在 Source set 上看到的):

新建资源目录

I've created the mipmap folder because it's the folder for placing your app/launcher icons in only.我创建了 mipmap 文件夹,因为它是仅用于放置应用程序/启动器图标的文件夹。 All the other images should be placed in the drawable folders.所有其他图像应放置在可绘制文件夹中。

Add the ic_launcher icon to the folder created (app > src > res > mipmap > ic_launcher.png).将 ic_launcher 图标添加到创建的文件夹(app > src > res > mipmap > ic_launcher.png)。

在此处输入图片说明

Now, just reference your icon on your AndroidManifest as below:现在,只需在您的 AndroidManifest 上引用您的图标,如下所示:

<application
    android:name=".MyApplication"
    android:icon="@mipmap/ic_launcher"
    ...
</application>

And the magic is done!魔术就完成了!

据我所知,应用程序图标仅依赖于它们所在的 drawables 文件夹,并且没有用于 -debug 的文件夹限定符,并且您无法根据清单更改来更改图标

a bit late (actually about 8 years), but while I was browsing DuckDuckGo's Android source code today, I found out that they do it this way:有点晚(实际上大约 8 年),但是当我今天浏览DuckDuckGo 的 Android 源代码时,我发现他们是这样做的:

in your app/build.gradle:在你的 app/build.gradle 中:

android {
    ...
    buildTypes {
        debug {
            ...
            manifestPlaceholders = [
                    appIcon: "@mipmap/ic_launcher_blue",
                    appIconRound: "@mipmap/ic_launcher_blue_round"
            ]
        }
        release {
           ...
            manifestPlaceholders = [
                    appIcon: "@mipmap/ic_launcher_red",
                    appIconRound: "@mipmap/ic_launcher_red_round"
            ]
        }
    }
    ...
}

and in your AndroidManifest.xml just use:并在您的 AndroidManifest.xml 中使用:

<application
     ...
     android:icon="${appIcon}"
     android:roundIcon="${appIconRound}"
     ...
/>
   ...
</application>

You need gradle and build flavors to do this.你需要 gradle 和 build flavors 来做到这一点。 Then you can have different resource folders for the different flavors.然后,您可以为不同的风格设置不同的资源文件夹。

http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Product-flavors

I know this is an old question - but if anyone else searches for this...我知道这是一个老问题 - 但如果其他人搜索这个......

You can do this by creating a debug manifest (src/debug/AndroidManifest.xml) and updating its properties.您可以通过创建调试清单 (src/debug/AndroidManifest.xml) 并更新其属性来完成此操作。

See: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Markers请参阅: http : //tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Markers

Whereas the response by Alex is fine in case flavors are not in use, for getting different icons while using different flavors with multiple dimensions, such as:而 Alex 的响应在不使用风味的情况下很好,用于在使用具有多个维度的不同风味时获得不同的图标,例如:

flavorDimensions "color", "size"
productFlavors {
    black {
        dimension "color"
    }
    white {
        dimension "color"
    }

    big {
        dimension "size"
    }
    small {
        dimension "size"
    }
}

This can be achieved as:这可以通过以下方式实现:

First, put the debug resources in separate folders, such as:首先,将调试资源放在单独的文件夹中,例如:

src/blackDebug/res
src/whiteDebug/res

Second, put the key with multiple flavor dimensions is that the sourceset name must contain all the possible flavor combinations, even if some of these dimensions do not affect the icon.其次,放置多个风味维度的关键是源集名称必须包含所有可能的风味组合,即使其中一些维度不影响图标。

sourceSets {
    // Override the icons in debug mode
    blackBigDebug.res.srcDir 'src/blackDebug/res'
    blackSmallDebug.res.srcDir 'src/blackDebug/res'
    whiteBigDebug.res.srcDir 'src/whiteDebug/res'
    whiteSamllDebug.res.srcDir 'src/whiteDebug/res'
}

Just to make it clear, the following will not work when multiple dimensions are in use:只是为了清楚起见,当使用多个维度时,以下内容将不起作用

sourceSets {
    // Override the icons in debug mode
    blackDebug.res.srcDir 'src/blackDebug/res'
    whiteDebug.res.srcDir 'src/whiteDebug/res'
}

A simple solution without fiddling gradle :一个无需摆弄gradle简单解决方案:

create a folder debug under module_name/src then under debug create folder res/drawable or res/mipmap and put your debug icon there.module_name/src下创建一个文件夹debug然后在debug下创建文件夹res/drawableres/mipmap并将您的调试图标放在那里。

When you finished the above there won't be an extra "res" folder for the debug resources, but you'll see the "debug" annotation alongside your resources, like this:完成上述操作后,调试资源将不会有额外的“res”文件夹,但您会在资源旁边看到“debug”注释,如下所示:

在此处输入图片说明

(the second ic_launcher.xml is placed under src/debug/res/mipmap and it uses an adaptive background in src/debug/res/drawable ) (第二个ic_launcher.xml放在src/debug/res/mipmap ,它在src/debug/res/drawable使用自适应背景)

Thus when the build variant is selected to debug, you'll see the icon is the debug icon you provided and when the build variant is set to release, you'll have the release icon. Thus when the build variant is selected to debug, you'll see the icon is the debug icon you provided and when the build variant is set to release, you'll have the release icon.

Proved and used in production.在生产中得到验证和使用。

You may try having two different app icons in your drawable folder - namely:您可以尝试在 drawable 文件夹中有两个不同的应用程序图标 - 即:

  1. drawable/app_icon_release drawable/app_icon_release
  2. drawable/app_icon_debug drawable/app_icon_debug

When setting debug mode to true:将调试模式设置为 true 时:

<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
        <application 
            android:debuggable="true"
            android:icon="@drawable/app_icon_debug"
            android:label="Your App Name" >

        </application>  
</manifest>
</android>

Otherwise, when debug mode to false:否则,当调试模式为 false 时:

<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
        <application 
            android:debuggable="false"
            android:icon="@drawable/app_icon_release"
            android:label="Your App Name" >

        </application>  
</manifest>
</android>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在发布模式下调试Android应用程序? - How to debug android app on release mode? 为什么我的(android)phonegap应用程序可以在调试模式下工作,而不能在发布模式下工作? - Why my (android) phonegap app works on debug mode but not on release mode? Android应用程式在侦错模式下运作良好,但在发布模式下当机 - Android app working fine in debug mode but crashing in release mode 在调试模式下运行的同一Android应用程序在发布模式下崩溃 - Same Android app who runs on Debug mode, crashes on release mode 如何使用 Android Studio 在发布模式下调试 Android 应用程序 - How to debug the Android App in release mode using Android studio 在调试和发布模式下都允许从Android应用程序进行Api访问 - Allow Api Access for Android App From Both in Debug and Release Mode Android App在调试中工作,但在发布模式下不起作用 - Android App works in debug but doesn't work in release mode 如何调试仅在发布模式下崩溃的 Android 应用 - How do I debug an Android app that crashes only in Release Mode 应用程序在调试模式下工作,但在发布模式下不工作 - App works on Debug mode, but not work on Release mode 不同行为的调试与发布模式android —发布模式冻结 - Different behaviour debug vs release mode android — release mode freezes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM