AndroidStudio 3.X 自定义Lint代码检查

创建Java Module,配置其gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apply plugin: 'java-library'


sourceCompatibility = "1.7"
targetCompatibility = "1.7"


jar {
manifest {
attributes("Lint-Registry-v2": "me.jiahuan.androidlearn.clint.CIssueRegistry")
}
}

dependencies {
compileOnly "com.android.tools.lint:lint-api:26.1.2"
compileOnly "com.android.tools.lint:lint-checks:26.1.2"
}

创建Android Library Module,配置其gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apply plugin: 'com.android.library'

android {
compileSdkVersion common.compileSdkVersion

defaultConfig {
minSdkVersion common.minSdkVersion
targetSdkVersion common.targetSdkVersion
versionCode common.versionCode
versionName common.versionName
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
lintChecks project(':clint')
}

参考

https://www.jianshu.com/p/a297714bb99b
美团外卖https://zhuanlan.zhihu.com/p/35608859
https://medium.com/@vanniktech/writing-your-first-lint-check-39ad0e90b9e6