dagger2&&databinding&&lamada

android {
....
dataBinding {
enabled = true
}

defaultConfig {
...
jackOptions {//The Jack toolchain is deprecated, until the new replacement.
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile 'com.google.dagger:dagger-android:2.x'
compile 'com.google.dagger:dagger-android-support:2.x' // if you use the support libraries
annotationProcessor 'com.google.dagger:dagger-android-processor:2.x'
}

android.applicationVariants.all { variant ->

// launch after install
if (variant.install != null) {
tasks.create(name: "run${variant.name.capitalize()}", type: Exec, dependsOn: variant.install) {
description "Installs the APK for ${variant.description}, and then runs the main launcher activity."
def getMainActivity = { file ->
new XmlSlurper().parse(file).application.activity.find{ it.'intent-filter'.find{ filter ->
return filter.action .find{it.'@android:name'.text() == 'android.intent.action.MAIN' } \
&& filter.category.find{it.'@android:name'.text() == 'android.intent.category.LAUNCHER'}
}}.'@android:name'
}
variant.install.doLast {
def activityClass = getMainActivity(variant.outputs.processManifest.manifestOutputFile)
println variant.name.capitalize()
println activityClass
commandLine android.adbExe, 'shell', 'am', 'start', '-n', "${variant.applicationId}/${activityClass}"

}
}
}

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注