达到65k方法限制后,Kotlin的View Binding扩展会停止工作,并在引用视图时抛出NullPointerException。
我尝试安装MultiDex,但它没有解决问题。
我正在使用Android API 25,不使用ProGuard并编译调试风格。我能做什么?
以下是错误的示例
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jj.pos, PID: 5906
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jj.pos/com.jj.pos.features.authentication.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.jj.pos.features.authentication.GoogleAuthenticator.loadBusinessAndGoToMainActivity(GoogleAuthenticator.kt:42)
at com.jj.pos.features.authentication.GoogleAuthenticator.<init>(GoogleAuthenticator.kt:35)
at com.jj.pos.features.authentication.LoginActivity.onCreate(LoginActivity.kt:18)
at android.app.Activity.performCreate(Activity.java:6720)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
这是我的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.jj.pos"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
// Additional android libraries
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
// MultiDex
implementation 'com.android.support:multidex:1.0.2'
// Memory leaks
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
// Firebase
implementation 'com.google.firebase:firebase-auth:11.6.2'
implementation 'com.google.android.gms:play-services-auth:11.6.2'
implementation 'com.google.firebase:firebase-firestore:11.6.2'
implementation 'com.google.firebase:firebase-crash:11.6.2'
// RxJava
// implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Images loader and cache
implementation 'com.squareup.picasso:picasso:2.5.2'
// Decent datetime API
implementation 'joda-time:joda-time:2.9.9'
// Animations
compile 'com.android.support:support-compat:26.1.0'
compile 'com.daimajia.easing:library:2.0@aar'
compile 'com.daimajia.androidanimations:library:2.3@aar'
// UI
compile 'com.github.markushi:circlebutton:1.1' // -- FAB
implementation project(':btsdk')
implementation project(':zixng')
}
apply plugin: 'com.google.gms.google-services'
这是我的应用程序实现
class App : Application() {
override fun onCreate() {
super.onCreate()
MultiDex.install(this)
// Other configs like LeakCanary, Firestore and RxJavaErrorHandler
}
}
答案 0 :(得分:2)
清理项目解决了这个问题。