简体   繁体   English

APK 文件在 android 模拟器中工作,但不会安装在我的设备上

[英]APK File works in android emulator but won't install on my device

I'm new to Android Studio (downloaded it yesterday on my Windows 7 machine) and just finished creating an app using Kotlin.我是 Android Studio 的新手(昨天在我的 Windows 7 机器上下载了它)并且刚刚使用 Kotlin 创建了一个应用程序。 It works properly on the Android Emulator, but when I build a signed APK file and try installing it on my Samsung S7 (Android 8.0.0) phone it shows the mysterious error "App not installed".它在 Android 模拟器上正常工作,但是当我构建一个签名的 APK 文件并尝试将它安装到我的三星 S7 (Android 8.0.0) 手机上时,它显示神秘的错误“App not installed”。

I noticed there's a red X mark near MainActivity in the top bar, maybe it has something to do with the problem?我注意到顶部栏的 MainActivity 附近有一个红色的 X 标记,可能与问题有关? It doesn't prevent me from building...它不会阻止我建造......

红 X 截图

Previous builds of the same app installed properly.相同应用程序的先前版本已正确安装。 The only thing I changed before it started breaking is the location of the AVD folder (using this ) from the C drive to the D drive, since I ran out of memory there.在它开始崩溃之前我唯一改变的是 AVD 文件夹的位置(使用这个)从 C 驱动器到 D 驱动器,因为我在那里用完了内存。 I deleted all virtual devices, created the environment variable then created the virtual devices again.我删除了所有虚拟设备,创建了环境变量,然后再次创建了虚拟设备。

Things I already tried without any luck:我已经尝试过但没有运气的事情:

  • The top 5 solutions here 这里的前 5 个解决方案
  • Deleting debug.keystore删除 debug.keystore
  • Cleaning and rebuilding the project清理和重建项目
  • Changing the build variant to "Release"将构建变体更改为“发布”

EDIT: I created a new project and copied my scripts to there, and it now works properly.编辑:我创建了一个新项目并将我的脚本复制到那里,现在它可以正常工作了。 Not really a solution since this took a lot of time, but it solved the problem.不是真正的解决方案,因为这花了很多时间,但它解决了问题。

You should have to create new sample project and check it will be working or not您应该必须创建新的示例项目并检查它是否有效

If you have install apk before in your device you can not install it again如果您之前在设备中安装过 apk,则无法再次安装

For fix that为了解决这个问题

1) You can uninstall app from device and reinstall from apk. 1)您可以从设备卸载应用程序并从 apk 重新安装。

2) You can change versionCode in build.gradle(app) 2)您可以在 build.gradle(app) 中更改versionCode

defaultConfig {
    applicationId your_package_name   
    versionCode 2 //try to increase every time
    versionName "1.0.0" //no need to change but better change it
    //other codes
}
  1. Select the MainActivity(with X mark)选择 MainActivity(带有 X 标记)
  2. A dropdown will appear将出现一个下拉菜单
  3. Select your application Module (By Default it is app )选择您的应用程序模块(默认情况下是app
  4. Run the Project (It should install the apk and run on your device)运行项目(它应该安装 apk 并在您的设备上运行)

Hope it helps!!希望能帮助到你!!

Try it by delete .iml file from your project directory and rebuild project通过从项目目录中删除.iml文件并重建项目来尝试

Have you restart your system after updating location of AVD ?更新AVD位置后是否重新启动系统?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM