Android 生成的apk崩溃

Android 生成的apk崩溃,android,Android,我刚刚完成我的上一个android项目,但我面临一个奇怪的问题。一直以来,我都在使用这个应用程序,我总是通过点击那个绿色按钮在我的设备上运行它,它工作得很好。但现在我已经创建了我的应用程序的apk文件,它可以毫无问题地安装在设备上,但在我想启动应用程序时,它崩溃了,再也无法启动 任何帮助都将不胜感激。谢谢 更新:依赖项: implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.k

我刚刚完成我的上一个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 ""
    }
}
val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
    createdImageFile = model.returnImagePath()
    if (createdImageFile != ""){
        //do sth with the image file path
    }
视图模型类:

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 ""
    }
}
val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
    createdImageFile = model.returnImagePath()
    if (createdImageFile != ""){
        //do sth with the image file path
    }
视图模型用法:

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 ""
    }
}
val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
    createdImageFile = model.returnImagePath()
    if (createdImageFile != ""){
        //do sth with the image file path
    }

解决方案:

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 ""
    }
}
val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
    createdImageFile = model.returnImagePath()
    if (createdImageFile != ""){
        //do sth with the image file path
    }
而不是:

val model = ViewModelProviders.of(this).get(MyImageViewModel::class.java)
写:

var model: MyImageViewModel()
那么


试试看,希望它能起作用。

感谢所有试图帮助我的人,我发现了这个问题。这是一件很愚蠢的事。ViewModel类不应是私有的!就是这样。

在发布apk时,您选择了v1和v2吗?@UmangBurman我选择了两个选项:将手机连接到笔记本电脑,打开android studio,然后启动安装在手机上的应用程序,检查logcat有什么要说的,然后在这里发布。@Robert谢谢您的评论,但这并没有解决问题problem@UmangBurman谢谢你花了这么多时间,伙计。看看我的回答没什么对不起changed@Soroush对不起,我没有这样的错误。。事实上,我用了你的代码,你的依赖,所有的东西。应用程序运行良好。我的设备Moto X Play。我制作了apk,在内部存储中复制,安装时打开良好。@Soroush尝试一下:“'implementation'android.arch.lifecycle:viewmodel:1.1.1'-ktx implementation'android.arch.lifecycle:extensions:1.1.1'-ktx”很好。。。它在我的设备中是如何工作的?你能回答这个问题吗?好吧,恭喜它成功了,但我不认为初始化取决于私有或公共。不管怎样,我在其他主题中也看到过。哦,好吧,也许我在我的应用程序中实现了公共类。。我想我没有注意到。