로직을 깨끗이 유지하기 위해 별도의 .gradle
파일로 이동하려는 기능을 가진 파일이 긴 build.gradle
입니다. 문서는이 경우에 external build scripts을 사용할 것을 제안합니다. 이 build.gradle
파일에 배치 될 때 코드 로직, 그것은 잘 작동 문제가되지 않습니다build.gradle 로직을 .gradle 파일로 분할하는 방법은 무엇입니까?
android{
buildTypes {
debug {
signingConfig = loadFromPropertiesFile("DEBUG_KEY_PROPERTIES")
}
}
}
import com.android.builder.signing.DefaultSigningConfig
import com.android.builder.model.SigningConfig
SigningConfig loadFromPropertiesFile(keyProperty) {
// Load signing config from singning properties file
println keyProperty
println ("${keyProperty}")
if (project.hasProperty(keyProperty)) {
File releasePropsFile = new File(project.property(keyProperty))
println("Loading config from properties file: ${releasePropsFile}")
if (releasePropsFile.exists()) {
Properties releaseProps = new Properties()
releaseProps.load(new FileInputStream(releasePropsFile))
println releaseProps
def signingConfig = new DefaultSigningConfig(keyProperty)
signingConfig.storeFile = file(releasePropsFile.getParent() + "/" + releaseProps['keystore.file'])
signingConfig.storePassword = releaseProps['keystore.password']
//signingConfig.storeType = 'PKCS12'
signingConfig.keyAlias = releaseProps['alias.name']
signingConfig.keyPassword = releaseProps['alias.password']
return signingConfig
} else {
println("Can't read configuration file: ${releasePropsFile}")
return null
}
} else {
println("Project has not define configuration file: ${keyProperty}")
return null
}
}
: 나는 build.gradle
파일에서 다음 기능을 가지고있다. 내가 다음 오류가있어
apply from: "$rootDir/gradle/android-signing.gradle"
:
Cannot cast object 'DefaultSigningConfig{..}' with class
com.android.builder.signing.DefaultSigningConfig' to class
'com.android.builder.model.SigningConfig'
를 기본적으로 그것이 인터페이스에 구현을 캐스팅 할 수 있다고 나는 외부 파일에이 방법을 이동로를 포함하지만 실패합니다 . DefaultSigningConfig가 SigningConfig를 구현하기 때문에 see here. 어떤 의미가 없어, 다음에 보일 때까지 answer.
Two classes are treated as entirely different classes, even if they have the same package and name (and even implementation/fields/methods) when loaded by different classloaders. Which is the case when you are using plugin or external build script.
하지만, 내가 모듈 별도의 파일로 build.gradle
에서 방법을 분할 할 수있는 방법?
당신이에서 적용 사용합니까 때? loadFromPropertiesFile 메서드 만 정의합니까? android {} 절을 사용하고 상대 클래스 인 경우 cal을 적용하기 전에 android 플러그인을 적용했는지 확인해야합니다! apply from은 정의 된 경우 지역 변수가 전달되지 않는다는 점을 제외하면 기본적으로 include와 같습니다. – codeScriber
@Sergii Pechenizkyi 이제까지이 작업을 해보았습니까? –