I added an (experimental) hack to one of the android plugin’s tasks using metaprogramming. This works as long as I put it inside my build.gradle. I would like to move it into a separate script that I then apply though. This does fail with some “property not found” error, seems the class I reference can not be resolved.
Do scripts load from a different classpath (seems the class can not be resolved)? And is there a away to make this work?
Here is the hack:
// amend task "signingReport" to show base64-encoded hashes (as needed for app registration at Facebook)
def signingTaskMetaClass = com.android.build.gradle.internal.tasks.SigningReportTask.metaClass
if (!signingTaskMetaClass.properties.find { it.name == 'enhanced' }) {
signingTaskMetaClass.enhanced = true
MetaMethod metaFinger = signingTaskMetaClass.getStaticMetaMethod('getFingerprint', java.security.cert.Certificate, String)
signingTaskMetaClass.static.getFingerprint = { java.security.cert.Certificate cert, String hashAlgorithm ->
def base64 = java.security.MessageDigest.getInstance(hashAlgorithm).digest(cert.encoded).encodeBase64()
metaFinger.invoke(delegate, cert, hashAlgorithm) + "\n$hashAlgorithm (base64): $base64"
}
}
And this is the error when applied from a separate file (via apply from:) :
Could not find property 'com' on project ':mobile'.