Nikhilesh Patve
Nikhilesh Patve

Reputation: 1870

How to simply install apk in device in Android Studio

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.

Upvotes: 37

Views: 120397

Answers (10)

paul mccollum
paul mccollum

Reputation: 21

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

Upvotes: 2

Andrew Glukhoff
Andrew Glukhoff

Reputation: 916

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

Upvotes: 0

Kexi He
Kexi He

Reputation: 71

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

Upvotes: 1

admizh
admizh

Reputation: 59

  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

Upvotes: 5

Youssouf
Youssouf

Reputation: 1

  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.

Upvotes: 0

Gautam Chibde
Gautam Chibde

Reputation: 1227

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.

Upvotes: 5

Alexander Tumanin
Alexander Tumanin

Reputation: 1842

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.

Upvotes: 0

Eselfar
Eselfar

Reputation: 3869

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.)

Upvotes: 1

Avijeet
Avijeet

Reputation: 1051

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.

Upvotes: 53

Ali Bdeir
Ali Bdeir

Reputation: 4375

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.

Upvotes: 7

Related Questions