kotlin 当minifyEnabled在版本变体上为true时,应用程序因未知参数而崩溃

smdncfj3  于 2022-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(173)

在我的项目中,当我在release variant上将minifyEnabled设置为true时,我会在日志中看到崩溃

java.lang.NullPointerException: Parameter specified as non-null is null: method ve.m.F, parameter <this>
    at ve.m.F(Unknown Source:2)
    at v7.a.b(SourceFile:4)
    at com.myapp.features.screen.auth.welcome.a.invoke(SourceFile:3)
    at m0.b.invoke(SourceFile:1)
    at b0.x5$a.invoke(SourceFile:22)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at b0.x5.a(SourceFile:12)
    at com.myapp.features.screen.auth.welcome.b.invoke(SourceFile:5)
    at m0.b.invoke(SourceFile:1)
    at b0.k2.a(Unknown Source:52)
    at b0.i2.invoke(SourceFile:1)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at b0.q7.a(Unknown Source:94)
    at b0.j2$a.invoke(SourceFile:3)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at b0.j2.a(SourceFile:90)
    at r7.c.a(SourceFile:3)
    at com.myapp.features.screen.auth.welcome.WelcomeActivity$a.invoke(SourceFile:7)
    at m0.b.invoke(SourceFile:1)
    at androidx.compose.ui.platform.t0.a(Unknown Source:25)
    at androidx.compose.ui.platform.a$a.invoke(SourceFile:1)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at androidx.compose.ui.platform.u0.a(SourceFile:4)
    at androidx.compose.ui.platform.a0$i.invoke(SourceFile:1)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at androidx.compose.ui.platform.a0.a(SourceFile:18)
    at androidx.compose.ui.platform.a3.invoke(SourceFile:3)
    at m0.b.invoke(SourceFile:1)
    at f0.y.a(Unknown Source:30)
    at androidx.compose.ui.platform.b3.invoke(SourceFile:15)
    at m0.b.invoke(SourceFile:1)
    at e.b.q(Unknown Source:21)
    at f0.i$i.invoke(SourceFile:4)
    at e.b.w(SourceFile:3)
    at f0.i.Z(SourceFile:12)
    at f0.i.U(Unknown Source:13)
    at f0.v.y(SourceFile:2)
    at f0.n1.a(SourceFile:4)
    at f0.v.n(Unknown Source:10)
    at androidx.compose.ui.platform.WrappedComposition$a.invoke(SourceFile:10)
    at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(Unknown Source:11)
    at androidx.compose.ui.platform.WrappedComposition.n(Unknown Source:12)
    at androidx.compose.ui.platform.WrappedComposition.l(Unknown Source:18)
    at androidx.lifecycle.v$a.a(Unknown Source:14)
    at androidx.lifecycle.v.a(Unknown Source:92)
    at androidx.compose.ui.platform.WrappedComposition$a.invoke(SourceFile:8)
    at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(SourceFile:4)
    at android.view.View.dispatchAttachedToWindow(View.java:21976)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4293)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4302)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4302)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4302)
    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4302)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3469)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2919)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10491)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1108)
    at android.view.Choreographer.doCallbacks(Choreographer.java:866)
    at android.view.Choreographer.doFrame(Choreographer.java:797)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1092)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

当我转到“源文件:7”时,它指向组件活动中的“导入androidx。活动。合成。设置内容”。
我的活动如下所示;

import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview 
import com.myapp.MyApp
import com.myapp.features.navigation.WelcomeNavGraph
import com.myapp.ui.theme.Theme
import com.myapp.utils.managers.DataManager
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class WelcomeActivity : ComponentActivity() {

@Inject
lateinit var application: MyApp

@Inject
lateinit var dataManager: DataManager

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        application.isDark.value = isSystemInDarkTheme()
        Theme(darkTheme = application.isDark.value) {
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = MaterialTheme.colors.background
            ) {
                WelcomeNavGraph(applicationTexts = dataManager.languageMap!!)
            }
        }
    }
}

}

@Preview(
    showBackground = true,
    name = "Light Mode"
)
@Preview(
    showBackground = true,
    uiMode = Configuration.UI_MODE_NIGHT_YES,
    name = "Dark Mode"
)
@Composable
fun WelcomeActivityPreview() {
}

我编写版本是implementation 'androidx.activity:activity-compose:1.4.0'
我的Gradle文件如下所示;

buildTypes {
    release {
        productFlavors.prod.signingConfig signingConfigs.prod
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }

    debug {
        productFlavors.prod.signingConfig signingConfigs.prod
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.stage'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
    useIR = true
}
buildFeatures {
    compose true
}
composeOptions {
    kotlinCompilerExtensionVersion compose_version
    kotlinCompilerVersion '1.5.21'
}
packagingOptions {
    resources {
        excludes += '/META-INF/{AL2.0,LGPL2.1}'
    }
}

我研究了这个崩溃,很多人通过在www.example.com中添加一些-keep规则来解决它proguard-rules.pro
在这种情况下,我能做些什么来解决这个问题?PS:我是喷气背包作曲新来
谢谢你的回答。

l7wslrjt

l7wslrjt1#

我认为您已经在没有任何proguard规则的情况下将minifyEnabled设置为true,请尝试添加该规则。

相关问题