1 Star 0 Fork 0

栉风 / android-environment-variable

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

这是一个简单易用的环境变量管理库,类似EnvironmentSwitcher
知之非艰,行之惟艰。

欢迎star、pr、issues

功能

  • 支持多个配置文件,对组件化友好

  • 配合build variant,配置默认值可跟随打包变化

  • 支持隐藏非当前build variant配置,不暴露私有配置数据

  • 自带配置切换ui实现,并支持自定义输入配置项值

如何使用

// 根目录build.gradle
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

// 要使用的模块build.gradle添加:

// 可选,用于跟随打包环境
android {
    buildTypes {
        debug {
            buildConfigField("String", "EV_VARIANT", "\"dev\"")
        }
        release {
            buildConfigField("String", "EV_VARIANT", "\"release\"")
        }
    }
}

// 添加依赖
dependencies {
    implementation 'com.github.hcanyz.android-environment-variable:environment-variable-setting:${version}'
    //不需要设置页面 implementation 'com.github.hcanyz:android-environment-variable:${version}'

    kapt 'com.github.hcanyz.android-environment-variable:compiler:${version}'
    // java annotationProcessor 'com.github.hcanyz.android-environment-variable:compiler:${version}'
}

编写配置类(支持java、kotlin)

@EvGroup(defaultVariant = BuildConfig.EV_VARIANT)
class EvCoreConfig {
    @EvItem
    class ServerUrl {
        @EvVariant(desc = "dev server url")
        val dev: String = "https://dev.hcanyz.com"

        @EvVariant(desc = "uat server url")
        val uat: String = "https://uat.hcanyz.com"

        @EvVariant(desc = "release server url")
        val release: String = "https://hcanyz.com"

        // 用于初期开发api mock
        @EvVariant(desc = "mock url")
        val _customize_: String = "http://localhost:8080"
    }

    @EvItem
    class H5BaseUrl {

        @EvVariant(desc = "h5 dev server url")
        val dev: String = "https://h5-dev.hcanyz.com"

        @EvVariant(desc = "h5 uat server url")
        val uat: String = "https://h5-uat.hcanyz.com"

        @EvVariant(desc = "h5 release server url")
        val release: String = "https://h5.hcanyz.com"

        @EvVariant(desc = "h5 tmp server url")
        val tmp: String = "https://h5-tmp.hcanyz.com"
    }
}

完成编译后会生成一个 com.hcanyz.android_kit.widget.core.EvCoreConfigManager

获取 ServerUrl

EvCoreConfigManager.getSingleton(appContext)
    .getEvItemCurrentValue(EvCoreConfigManager.EV_ITEM_SERVERURL)

跳转到设置页面

EvSwitchActivity.skip(context, arrayListOf(EvCoreConfigManager::class.java))



---

android-kit 致力于为android关键场景提供解决方案。

MIT License Copyright (c) 2020 hcanyz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

这是一个简单易用的环境变量管理库,类似 https://github.com/CodeXiaoMai/EnvironmentSwitcher 展开 收起
Java 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/hcanyz/android-environment-variable.git
git@gitee.com:hcanyz/android-environment-variable.git
hcanyz
android-environment-variable
android-environment-variable
master

搜索帮助