Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

Android Studio 3.1 "Run" not compiling code

When I try to install an app, there are two possibilities:

  1. Install existing APK from build folder when I run the app
  2. Install APK after performing clean build

For existing APK in the build folder, the app just works fine. But when I clean the project using Build -> Clean Project, and then try to run the app (i.e. install the app to my emulator or physical device), it shows me error:

The APK file /Users/MyApplicationName/app/build/outputs/apk/app-debug.apk does not exist on disk.

NOTE: This behaviour happens only when I clean the project and not when I have already have a pre-built app APK in my build folder

I've referred to: The APK file does not exist on disk but my point is, when we usually run the app after cleaning the project, we never need to make a build of it, if the APK is not existing in the build folder, it automatically generates and installs the latest one.

Things I've tried:

  1. Running the app when APK file exists in the build folder (works perfectly fine)
  2. Running the Clean Project -> Running the app (expected is the project would be built and the app would get installed but it shows the above mentioned error!)
  3. Same process of cleaning and running the app after doing Invalidate Caches/Restart
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have solution for your issue. Hope it helps!

Also confirmed by Android Studio on Twitter : https://twitter.com/androidstudio/status/981914632892960768

1) Please edit your app configuration as below.

enter image description here

2) Here you can see your app configuration as below.

enter image description here

3) Here is missing Gradle-aware make attribute in before launch configuration. You can see here.

enter image description here

4) Please add this Gradle-aware Make attribute through this way. Click on + icon and select Gradle-aware Make as seen in this screen.

enter image description here

5) You can add this without writing any task just press OK button and task will be added and now it should look like this. Now apply changes and run your application.

enter image description here

Hope it will solve this old apk installing issue on clean build in new android studio 3.1 issue.

Note : This issue is resolved in new Android Studio 3.1.1 Stable release.

Happy Coding!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...