20

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

4

9 回答 9

23

我参加聚会有点晚了,但无论如何。目前我在 16 年发布此内容,您实际上可以设置不同的启动图标,只需将它们放在各自的目录中,但不确定它在 13 年的情况如何。为此,您需要在app/src下创建debug/res目录,并将 mipmap 或可绘制目录放在那里。所以你会有app/src/main/res/app/src/debug/res/路径。Android 将对构建相关的资源目录具有更高的优先级 - 到目录。将您的调试和发布资源放置到适当的路径中,您就会得到想要的东西。考虑到您必须使用 Gradle 构建系统,请执行上述所有操作。

在这里你可以阅读更多关于这样的东西:http ://tools.android.com/tech-docs/new-build-system/resource-merging

于 2016-03-10T15:39:35.780 回答
5

有点晚了,但我会把我的解决方案留给正在寻找相同答案的人。

在定义buildTypesbuild.gradle上,我为我的 debug_test 构建类型添加了一个后缀,以便在我的设备上安装不同的 apk。

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

之后,转到 File > New > Android Resource Directory 并为您的 debug_test 构建类型创建一个新的 mipmap 资源目录(如您在 Source set 上所见):

创建新的资源目录

我创建了 mipmap 文件夹,因为它只是用于放置应用程序/启动器图标的文件夹。所有其他图像应放置在可绘制文件夹中。

将 ic_launcher 图标添加到创建的文件夹中(app > src > res > mipmap > ic_launcher.png)。

在此处输入图像描述

现在,只需在您的 AndroidManifest 上引用您的图标,如下所示:

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

魔术完成了!

于 2018-04-09T11:27:11.363 回答
4

有点晚了(实际上大约是 8 年),但是当我今天浏览DuckDuckGo 的 Android 源代码时,我发现他们是这样做的:

在你的app/build.gradle( DuckDuckGo'sapp/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"
            ]
        }
    }
    ...
}

并在您AndroidManifest.xml刚刚使用时(DuckDuckGo'sAndroidManifest.xml

<application
     ...
     android:icon="${appIcon}"
     android:roundIcon="${appIconRound}"
     ...
/>
   ...
</application>
于 2021-03-26T16:32:05.153 回答
1

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

于 2013-10-22T20:52:59.273 回答
1

你需要 gradle 和 build flavor 来做到这一点。然后,您可以为不同的风格拥有不同的资源文件夹。

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

于 2014-11-07T15:44:52.263 回答
1

我知道这是一个老问题 - 但如果其他人搜索这个......

您可以通过创建调试清单 (src/debug/AndroidManifest.xml) 并更新其属性来做到这一点。

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

于 2016-02-12T14:15:07.423 回答
0

而亚历克斯的反应很好,以防万一没有使用风味,在使用具有多个维度的不同风味的同时获得不同的图标,例如:

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

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

这可以通过以下方式实现:

首先,将调试资源放在单独的文件夹中,例如:

src/blackDebug/res
src/whiteDebug/res

其次,具有多个风味维度的关键是源集名称必须包含所有可能的风味组合,即使其中一些维度不会影响图标。

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'
}

为了清楚起见,当使用多个维度时,以下内容将不起作用:

sourceSets {
    // Override the icons in debug mode
    blackDebug.res.srcDir 'src/blackDebug/res'
    whiteDebug.res.srcDir 'src/whiteDebug/res'
}
于 2017-02-04T20:29:16.177 回答
0

一个简单的解决方案,无需摆弄gradle

然后在创建文件夹debug下创建一个文件夹,或者将您的调试图标放在那里。module_name/srcdebugres/drawableres/mipmap

完成上述操作后,调试资源不会有额外的“res”文件夹,但您会在资源旁边看到“debug”注释,如下所示:

在此处输入图像描述

(第二个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.

在生产中得到证明和使用。

于 2021-05-19T12:23:36.133 回答
-2

您可以尝试在您的可绘制文件夹中使用两个不同的应用程序图标 - 即:

  1. 可绘制/app_icon_release
  2. 可绘制/app_icon_debug

将调试模式设置为 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>

否则,当调试模式为 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>
于 2013-10-22T21:09:25.080 回答