簡體   English   中英

Android - 用於調試和發布模式的應用程序圖標

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

如果我們在清單中設置 android:debuggable=true 並且我們在 iOS 中設置 android:debuggable=false ,是否可以為應用程序設置單獨的圖標?

我參加聚會有點晚了,但無論如何。 目前我在 16 年發布此內容,實際上您可以設置不同的啟動圖標,只需將它們放在各自的目錄中即可,但不確定 13 年的情況如何。 為此,您需要在app/src下創建debug/res目錄並將 mipmap 或 drawable 目錄放在那里。 所以你會有app/src/main/res/app/src/debug/res/路徑。 Android 將具有更高優先級的構建相關資源目錄 - 到目錄。 將您的調試和發布資源放置到適當的路徑,您將擁有您想要的。 考慮到您必須使用 Gradle 構建系統,請執行上述所有操作。

在這里你可以閱讀更多關於這樣的東西: http : //tools.android.com/tech-docs/new-build-system/resource-merging

有點晚了,但我會為正在尋找相同答案的人留下我的解決方案。

在定義了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>

魔術就完成了!

據我所知,應用程序圖標僅依賴於它們所在的 drawables 文件夾,並且沒有用於 -debug 的文件夾限定符,並且您無法根據清單更改來更改圖標

有點晚(實際上大約 8 年),但是當我今天瀏覽DuckDuckGo 的 Android 源代碼時,我發現他們是這樣做的:

在你的 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"
            ]
        }
    }
    ...
}

並在您的 AndroidManifest.xml 中使用:

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

你需要 gradle 和 build flavors 來做到這一點。 然后,您可以為不同的風格設置不同的資源文件夾。

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

我知道這是一個老問題 - 但如果其他人搜索這個......

您可以通過創建調試清單 (src/debug/AndroidManifest.xml) 並更新其屬性來完成此操作。

請參閱: http : //tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Markers

而 Alex 的響應在不使用風味的情況下很好,用於在使用具有多個維度的不同風味時獲得不同的圖標,例如:

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

一個無需擺弄gradle簡單解決方案:

module_name/src下創建一個文件夾debug然后在debug下創建文件夾res/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.

在生產中得到驗證和使用。

您可以嘗試在 drawable 文件夾中有兩個不同的應用程序圖標 - 即:

  1. drawable/app_icon_release
  2. drawable/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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM