Android构建工具集:包含快速实现组件化构建脚本,快速实现屏幕最小宽度适配脚本
🍭wow Android辅助构建工具,机械性工作交给我来处理,把时间用在更有价值的工作上。
Android构建工具包,这个工具的主旨是使用脚本自动处理机械化的重复劳动,让开发者专注更有价值的工作。 目前提供自动组件化控制与屏幕适配插件。
组件化构建Gradle插件 插件包的名字叫: component,其中提供了两个组件化辅助插件,分别叫calces.appconfig和calces.modules。 主要的功能是: 提供Gradle配置App依赖的组件、配置组件是否能单独运行、实现多个依赖不同模块的App同时构建等。
屏幕适配插件 组件包的名字叫: screen,其中提供了calces.screen插件 主要功能是: 根据设计稿与配置,自动生成smallestWidth适配文件,让你从此不需要再关注屏幕适配。
给你一个全自动的屏幕适配方案(基于SW方案)!—— 解放你和UI的双手
引入依赖库 在Gradle 2.1及更高版本的插件构建脚本代码: 在项目的build.gradle中
buildscript {
...
}
plugins {
id "calces.appconfig" version "3.3.0-alpha01"
}
在较旧版本的Gradle中或需要动态配置的情况下的插件构建脚本代码:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.tangpj.tools:component:3.3.0-alpha01"
}
}
apply plugin: "calces.appconfig"
在项目build.gradle配置AppConfig
appConfig {
debugEnable true
apps {
app1 {
mainActivity "com.xxx.MainActivity1"
modules ':modules1',
':modules2'
}
app2 {
mainActivity "com.xxx.MainActivity2"
modules ':modules1'
}
}
modules {
modules1 {
applicationId "com.xxxx.modules1"
mainActivity ".Modules1Activity"
isRunAlone true
}
modules2 {
applicationId "com.xxxx.modules2"
mainActivity ".Modules2Activity"
isRunAlone true
}
}
}
在modules(子模块)引入模块自动化构建插件 (注意:不需要手动配置com.android.library或com.android.application)
apply plugin: 'calces.modules'
引入依赖库 在Gradle 2.1及更高版本的插件构建脚本代码: 在项目的build.gradle中
buildscript {
...
}
plugins {
id "calces.screen" version "1.3.4-alpha01"
}
在较旧版本的Gradle中或需要动态配置的情况下的插件构建脚本代码:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.tangpj.tools:screen:1.3.4-alpha01"
}
}
apply plugin: "calces.screen"
在需要适配的组建上build.gradle配置Screen值
screen{
auto true
dimens{
designPx 375
smallesWidths 360,480
scale 3 //保留小数位,默认为2
scaleMode BigDecimal.ROUND_HALF_UP //小数保留的方式
}
}
auto 是用来确认是否需要自动生成sw文件的,会影响编译时间,如果values没有更新的话建议设置为false。 除此之外,可以通过手动调用gradle任务来手动生成sw文件。
该开源项目包含了笔者关于Android进阶系列教程的示例代码,其中TodoCalces是该构建脚本的Demo。
AppConfig
debugEnable, 布尔值 是否开个debug模式,只有当debugEnbale为true时,modules的isRunAlone才能生效。即modoules只能在debug模式中独立启动
apps, String列表 app列表,控制当debug模式为false时的app数量与基础配置
modules, String列表 组件列表,配置需要实现自动组件化控制的组件列表
App(apps里面的配置项)
Modules(modules里的配置项)
name, String类型 与app中的name一致
isRunAlone, 布尔值 该组件能否独立启动
applicationId, String类型 独立启动时的applicationId
applicationName, String类型 配置启动Application(对应manifest中的application name属性)
mainActivity, String类型 独立启动的Activity
dimens( 自动化Sw屏幕适配方案配置 )
mipmap( 图片资源自动适配指定密度 )
主要目的是为了解耦,把组件化插件和屏幕适配插件分离。
组件化插件会依赖Android Build Plugin,所以从3.3.0版本开始,版本好会与Android Build Plugin保持一致,而alpha01则是calces.component自身的版本变化。
与1.2.52功能一样,唯一的区别是能单独依赖calces.screen包,不需要再依赖整个calces插件包
Copyright 2018 Tang.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.