V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
2bab
V2EX  ›  Android

ScratchPaper - 为 icon 和 apk 添加 build info 的 Gradle Plugin

  •  
  •   2bab · 2018-09-21 14:00:42 +08:00 · 3488 次点击
    这是一个创建于 2016 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目地址: https://github.com/2BAB/ScratchPaper

    欢迎 issues, PRs, any contributions

    ScratchPaper (v2.x)

    ScratchPaper 通过编译期动态修改 icon 和生成包括 git 信息在内的 assets,帮助你识别多个 buildTypes 或 flavors 生成的 APK 文件。

    • 支持 AAPT2
    • 支持 Instant Run
    • 纯 Kotlin 编写

    ScratchPaper 都做了些什么?

    如果你在一台设备上安装两个 App,一个是 Debug 版一个是 Release 版,那么你很难区分出来到底哪个是哪个(不打开的情况下)。

    ScatchPaper 可以在你的 App icon 上加一个蒙层用以区分出各个 buildTypes 的 App,并且承载了版本信息等附加文字。

    如果你同时打了多个测试包给测试或者产品(例如基于多个复合分支),当他们给你反馈的问题时候你和他们可能都很难分别出每个 App 对应的具体的分支或者 commit 节点。

    ScatchPaper 支持生成编译信息并打包到你的 Apk 中(从 assets 中读取),以及输出一份拷贝到 /intermedias/scratch-paper/assets 文件夹,包括:

    • Base: Build Time, Build Type, etc.
    • Git: Latest Commit ID & commit branch, etc.
    • Dependencies
    • ...

    为什么一定要试试 ScratchPaper

    其实市面上不乏有类似的解决方案,例如:akonior/icon-version, akaita/easylauncher-gradle-plugin。但是他们的问题在于:不支持 AAPT2 !由于 Google 会在 18 年底停止对 aapt1 的支持( enableAapt2=false 将被移除),所以尽早迁移到 AAPT2 其实是一个明智的选择。加上 AAPT2 的诸多好处:

    • 其实对 local debug build 时的性能是有一定提升的
    • 修复很多 AAPT1 的低级 Bug (我曾写过一个插件来修复各类 AAPT 处理 Manifest 时的 Bug,具体查阅 https://github.com/2BAB/Seal
    • 同样有办法支持插件化的开发

    ScratchPaper 希望不仅能给大家带来好用的 APK 识别解决方案,同时也跟大家一起探讨:

    • AAPT2 是怎么工作的
    • 如何在 Gradle 中进行资源编译的 Hook
    • ...

    如何使用?

    0x01. Add the plugin to classpath:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.4'
            classpath 'me.2bab:scratch-paper:2.1.1'
        }
    }
    

    0x02. Apply Plugin:

    // On Application's build.gradle (do not use in Library project)
    apply plugin: 'me.2bab.scratchpaper'
    

    0x03. Build your App and Enjoy!

    0x04. Advanced Configurations

    scratchPaper {
        textSize = 12
        textColor = "#FFFFFFFF"
        verticalLinePadding = 4
        backgroundColor = "#99000000"
        extraInfo = "This is a sample!"
        enableGenerateIconOverlay = true
        enableGenerateBuildInfo = true
        
        // Experimental field
        // @see IconOverlayGenerator#removeXmlIconFiles
        enableXmlIconRemove = false
    }
    
    第 1 条附言  ·  2018-09-21 14:32:11 +08:00

    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5296 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 09:20 · PVG 17:20 · LAX 02:20 · JFK 05:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.