首页 > 解决方案 > 生成的 apk 崩溃了

问题描述

我刚刚完成了我的最后一个 android 项目,但我遇到了一个奇怪的问题。我一直在开发该应用程序时,我曾经通过单击那个绿色按钮在我的设备上运行它,它运行良好。但是现在我已经创建了我的应用程序的 apk 文件,它可以毫无问题地安装在设备上,但是当我想启动应用程序时,它崩溃了并且永远不会启动。

任何帮助将不胜感激。谢谢。

更新:依赖项:

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-vector-drawable:26.1.0'
implementation 'com.android.support:preference-v14:26.1.0'
implementation 'com.github.codekidX:storage-chooser:2.0.4.2'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'android.arch.lifecycle:viewmodel:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:26.1.0'

视图模型类:

private class MyImageViewModel: ViewModel(){
    fun returnImagePath(): String{
        return createdImageFile
        //createdImageFile is a global string that contains the path of an image and its default value is ""
    }
}

ViewModel 用法:

val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
    createdImageFile = model.returnImagePath()
    if (createdImageFile != ""){
        //do sth with the image file path
    }

标签: android

解决方案


感谢所有试图提供帮助的人,我发现了问题。这是一件有点愚蠢的事情。ViewModel 类不应该是私有的!而已。


推荐阅读