Skip to content

Instantly share code, notes, and snippets.

@mmadev
Last active September 30, 2020 02:38
Show Gist options
  • Save mmadev/97716b29753aed299003 to your computer and use it in GitHub Desktop.
Save mmadev/97716b29753aed299003 to your computer and use it in GitHub Desktop.
Add multidex keep file support in the build.gradle
android.applicationVariants.all { variant ->
task "fix${variant.name.capitalize()}MainDexClassList" << {
logger.info "Fixing main dex keep file for $variant.name"
File keepFile = new File("$buildDir/intermediates/multi-dex/$variant.buildType.name/maindexlist.txt")
keepFile.withWriterAppend { w ->
// Get a reader for the input file
w.append('\n')
new File("${projectDir}/multidex.keep").withReader { r ->
// And write data from the input into the output
w << r << '\n'
}
logger.info "Updated main dex keep file for ${keepFile.getAbsolutePath()}\n$keepFile.text"
}
}
}
tasks.whenTaskAdded { task ->
android.applicationVariants.all { variant ->
if (task.name == "create${variant.name.capitalize()}MainDexClassList") {
task.finalizedBy "fix${variant.name.capitalize()}MainDexClassList"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment