34

My question is when i click on run button it runs gradle command to check change files and build class and then dex to create apk.

If i know there is no change in my files still gradle runs to check.

As i have many libraries attached to my app module to reduce run time. if anyone knows to install apk in device from android studio without running gradle.

Note : I want to install on device which is connected to my system not to emulator,etc.

Note : I want to install from android studio not by using any other software.

Nikhilesh Patve
  • 1,760
  • 3
  • 13
  • 31

10 Answers10

53

One more solution is using terminal to install apk on devices. Once you have built your APK using the File>Build APK, it shows you the path in which new apk is present.

Just go to the path on terminal like below generated apk path on my system -$cd /Android_App_Code/UpdatedCodeForCheckOut/Projects/IMS/source/apps/Android/flowtalk/app/build/outputs/apk

and type -$ adb install -r app-debug.apk

this command just installs the build on your connected device. and now every time when there is no change in code, just run install command on terminal. It's super fast you will see.

Avijeet
  • 1,031
  • 1
  • 10
  • 27
  • This seems to only work on `Linux`/`Unix` based OS. What about Windows? – derHugo Jun 07 '19 at 08:59
  • 1
    @derHugo It works on Windows. Make sure adb is in your path. Mine is at `C:\Users\myname\AppData\Local\Android\Sdk\platform-tools\adb` – simpleuser Jun 25 '19 at 23:15
  • Once again, project files have been moved around. As of Android Studio 3.5.3, the location of release version of the apk is `[my_project_directory]/app/release/` (on mac). Debug versions are in `[my_project_directory]/app/build/outputs/apk/debug/`. – SMBiggs Jan 30 '20 at 04:30
  • `-r` flag is to "replace existing application" for those interested. See `man adb` and search for `install`. – topher217 Mar 08 '22 at 05:14
6

You can't skip a Gradle build unless you want a constant APK that has no changes.

Go to File>Build APK. Then, Gradle will build once. After that, a bubble at the top-right corner will appear indicating a successful APK generation.

Bubble at the top-right of the page

Click "Show in explorer", copy the generated APK and move it to your connected device. Then, go on your device>Your File Manager>The APK you just moved. Click it and install the application. There you have it.

There is no way for you to run without a Gradle build, and you're not the only one who thinks it is utterly STUPID for a force rebuild every time you want to build an APK or run an app with no changes since the last build.

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
  • The OP isn asking: I want to install from android studio. And you suggests to install from device manually. – Alexander Tumanin Sep 23 '16 at 13:05
  • @AlexanderTumanin and my answer says "you can't" and includes an alternative that's better than your answer. I'll edit my question to fix a typo, I'd appreciate it if you remove your downvote since my answer is currently the best available. – Ali Bdeir Sep 23 '16 at 13:46
  • I don't find your alternative better because of amount of a manual operations instead of just press "RUN". What is OP's use case? I assume to start the same app on different devices (because the same app on the same device can just be restarted). In this case you suggest every time navigate in computer to copy the APK, then navigate in device, the install (perhaps with permission accept) and only then RUN. My way says, how you can start the app just pressing "RUN" in 2-5 seconds. There are some other boost options, e.g. like "--offline" flag. All is better than yours one. – Alexander Tumanin Sep 23 '16 at 14:44
  • Moreover, in my case the gradle builds nothing, just checks if any changes exist. That's because it is so fast – Alexander Tumanin Sep 23 '16 at 14:49
  • @AlexanderTumanin False. When disconnecting the device you must rebuild unless it is 21+ – Ali Bdeir Sep 23 '16 at 17:35
  • @AlexanderTumanin and you can't say your answer answers the OP's question specifically either. On some computers, even with Instant Run it takes 15 seconds to build. Moreover, the build has to restart on pre-lollipop devices. – Ali Bdeir Sep 23 '16 at 17:39
  • I just checked, you are right about disconnecting. I remove my downvote. But I still think, that my solution is faster then yours. You cant install the APK manually in 15 seconds. – Alexander Tumanin Sep 23 '16 at 19:57
  • @AlexanderTumanin Yours is correct if the device API 21+. So I removed my downote too. – Ali Bdeir Sep 24 '16 at 12:14
  • On latest versions of Android Studio it's **Build>Build APK** – kingPuppy Jan 10 '18 at 16:26
5

I use this method to install the generated APK to the device using bash script since I'm working on Linux(didn't try this on windows or os x).

When you run the app in the android studio the run tab will print out the commands which android studio uses to install the app on the device.

enter image description here

I just copy these commands into a file and save it as run.sh

run.sh

#!/bin/sh

adb push /home/gautam/sample/app/build/outputs/apk/debug/app-debug.apk /data/local/tmp/com.example.sample.sample
adb shell pm install -t -r "/data/local/tmp/com.example.sample.sample"
adb shell am start -n "com.example.sample.sample/com.example.sample.sample.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

save the file in you project directory(although you can keep it any where).also add it to you gitignore if you need. Then open you terminal in android studio and run the script file to install the APK.

chmod a+x run.sh 
./run.sh 

enter image description here

This will install the apk to the connected device. If more then one device are connected the script will throw error in which case you will have to provide the device id refer this.

Hope this helps.

Gautam Chibde
  • 1,167
  • 3
  • 14
  • 27
2
  1. Generate apk (gradle build)
  2. Select generated apk in the project tree
  3. Right-click to .apk -> install APK

via plugin: install apk enter image description here

enter image description here

admizh
  • 29
  • 1
  • 1
1

Actually you can. Just create a new Run/Debug configuration (Edit configuration on the drop down list on the left of the "Run" arrow). Then remove "Gradle-aware Make" in the "Before launch" section of your configuration.

To run this configuration you need to have an existing APK generated otherwise it doesn't work, as this new configuration will just install the existing one.)

Eselfar
  • 3,759
  • 3
  • 23
  • 43
1

For people who use Flutter, Do as the following instruction.

  1. Connect your Android device to your computer with a USB cable.
  2. Enter cd where is your application directory.
  3. Run flutter install.

Flutter: Install an APK on a device

Kexi He
  • 71
  • 1
  • 6
1

There's a much easier way now. Windows: To install an App that you you have the APK file for:

  1. Start the Device Emulator.
  2. Drag the .apk file onto the emulator.

EOL

0

In Android Studio 2.2 there is a new property "build cache". To install it you open gradle.properties file of your project and add there:

android.enableBuildCache=true

like described here

And if you have no changes, your gradle will build in few seconds.

EDIT: Description of Build Cache from here:

Android Studio 2.2 Beta 3 introduces a new build cache feature that can speed up build times (including full builds, incremental builds, and instant run) by storing and reusing files/directories that were created in previous builds of the same or different Android project.

In other words, Build Cache reuses unchanged files rather then rebuild them.

Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42
Alexander Tumanin
  • 1,638
  • 2
  • 23
  • 37
0
  1. If you haven't changed anything on your files and it's not the first time you run the app on the device, you can navigate to the app on your device and open it from there. If your device is connected to your computer, you would still be able to access logcat of the app.

  2. If the modifications you've done is on an existing file, like the layout or .java file or any file that already exist, you can simply click on the apply changes button which is besides the run button as shown: The apply changes button to the right of the run button in android studio

works with android 3.0.1 and later.

  1. If you've added any new resources or created a new java file or new activity, the you must run from scratch to rebuild the hgradle.
0

Just create new configuration "install" with Launch Options -> Launch: Nothing

Andrew Glukhoff
  • 898
  • 11
  • 9