build.gradle
文件中添加:
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.daemon369:android-infrastructure-application:1.3.0"
}
可以在https://mvnrepository.com/artifact/io.github.daemon369/android-infrastructure-application查询最新版本
如果遇到如下错误:
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
Adding support for Java 8 language features could solve this issue.
解决方法:
// build.gradle
android {
// ...
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
通用Application
实现,应用使用InfrastructureApp
或其子类来作为自定义Application
时,可以简化基础支持库的很多功能的使用
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.daemon.infrastructure.application.demo">
<application
android:name="me.daemon.infrastructure.application.InfrastructureApp">
...
</application>
</manifest>
package me.daemon.infrastructure.application.demo
import me.daemon.infrastructure.application.InfrastructureApp
class DemoApplication : InfrastructureApp() {
}
fun getString(@StringRes strId: Int): String {
return application.getString(strId)
}