Skip to content

Commit da7e95c

Browse files
committed
Check dependencies in plugin.
1 parent 262fbcc commit da7e95c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

virtualapk-gradle-plugin/src/main/groovy/com.didi.virtualapk/hooker/PrepareDependenciesHooker.groovy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,46 @@ class PrepareDependenciesHooker extends GradleTaskHooker<AppPreBuildTask> {
115115
FileUtil.saveFile(hostDir, "${taskName}-stripDependencies", stripDependencies)
116116
FileUtil.saveFile(hostDir, "${taskName}-retainedAarLibs", retainedAarLibs)
117117
FileUtil.saveFile(hostDir, "${taskName}-retainedJarLib", retainedJarLib)
118+
119+
checkDependencies()
120+
118121
Log.i 'PrepareDependenciesHooker', "Analyzed all dependencis. Get more infomation in dir: ${hostDir.absoluteFile}"
119122

120123
vaContext.stripDependencies = stripDependencies
121124
vaContext.retainedAarLibs = retainedAarLibs
122125
mark()
123126
}
124127

128+
void checkDependencies() {
129+
ArrayList<DependenceInfo> allRetainedDependencies = new ArrayList<>()
130+
allRetainedDependencies.addAll(retainedAarLibs)
131+
allRetainedDependencies.addAll(retainedJarLib)
132+
133+
ArrayList<String> checked = new ArrayList<>()
134+
135+
allRetainedDependencies.each {
136+
String group = it.group
137+
String artifact = it.artifact
138+
String version = it.version
139+
140+
// com.didi.virtualapk:core
141+
if (group == 'com.didi.virtualapk' && artifact == 'core') {
142+
checked.add("${group}:${artifact}:${version}")
143+
}
144+
145+
// com.android.support:all
146+
if (group == 'com.android.support' || group.startsWith('com.android.support.')) {
147+
checked.add("${group}:${artifact}:${version}")
148+
}
149+
150+
// com.android.databinding:all
151+
if (group == 'com.android.databinding' || group.startsWith('com.android.databinding.')) {
152+
checked.add("${group}:${artifact}:${version}")
153+
}
154+
}
155+
156+
if (!checked.empty) {
157+
throw new Exception("The dependencies [${String.join(', ', checked)}] that will be used in the current plugin must be included in the host app first. Please add it in the host app as well.")
158+
}
159+
}
125160
}

0 commit comments

Comments
 (0)