- Home /
Pushing without compiling
I got an android 2.2 device that often will throw me an error on the pushing process, after compiling the whole project. The compiling process does take about 3 minutes and whanever I get the error, I have to try again which sums linearly up on the time it takes to test on the device. I have no such issues with another android 3.1 device and all that is actually beyond the point:
Is there any way to skip the compiling step and just push / send the APK so I can hugely minimize this bottleneck?
Answer by Tseng · Oct 01, 2011 at 02:46 PM
Of course, since you have the Android SDK installed, you also have the Android Debug Bridge (adb.exe), which is somewhere in the platform-tools folder.
Just open the command line and type adb install YourGamesAPKFile.apk
(or if it doesn't work, adb install -r YourGamesAPKFile.apk
) and adb will push it on the device.
Now what would make this practially perfect would be a way to script this into unity! :D
Answer by PatHightree · Jul 30, 2012 at 03:31 PM
Here you go, just put this in a C# script in Assets/Editor.
The first time it asks you for the locations of the android debug bridge exe and the apk file. These are stored in the PlayerPrefs for subsequent runs.
P.S. I tried to post this as a comment, but the formatting was crap.
using System;
using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class BuildPlayer : MonoBehaviour {
[MenuItem("Build/Push To Android")]
public static void PushToAndroid() {
string apkLocation = PlayerPrefs.GetString("APK location");
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(apkLocation))
apkLocation = EditorUtility.OpenFilePanel("Find APK", Environment.CurrentDirectory, "apk");
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(apkLocation)) {
Debug.LogError("Cannot find .apk file.");
return;
}
PlayerPrefs.SetString("APK location", apkLocation);
string adbLocation = PlayerPrefs.GetString("Android debug bridge location");
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(adbLocation))
adbLocation = EditorUtility.OpenFilePanel("Android debug bridge", Environment.CurrentDirectory, "exe");
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(adbLocation)) {
Debug.LogError("Cannot find adb.exe.");
return;
}
PlayerPrefs.SetString("Android debug bridge location", adbLocation);
ProcessStartInfo info = new ProcessStartInfo {
FileName = adbLocation,
Arguments = string.Format("install -r \"{0}\"", apkLocation),
WorkingDirectory = Path.GetDirectoryName(adbLocation),
};
Process.Start(info);
}
}
You can get the Android SD$$anonymous$$ root path form the Editor Preferences:
EditorPrefs.GetString("AndroidSdkRoot")
Thanks to Bunny83 at this article for the hint
Answer by Antan · Apr 04, 2019 at 09:53 AM
Neat script. Makes it really fast to test an apk-only build on the phone.
Has anyone made a script that installs an obb-expansion file as well? I tried adding code for .obb to be handled the same as the apk-file, but that did not work out. ,Neat script. Makes it so fast to install an apk-only build.
How would I go about to install a build with an .obb-expansion file? I tried adding an obb-file the same way as the .apk-file was handled, but that did not work. The obb file is disregarded.
Has anyone made a script to install both apk and obb files?
Answer by makaka-org · Nov 27, 2020 at 09:24 PM
macOS fixed script (Unity 2019.4):
using System;
using System.IO;
using System.Diagnostics;
using UnityEngine;
using UnityEditor;
public class AndroidAPKInstaller: MonoBehaviour
{
[MenuItem("File/Install APK to Android")]
public static void PushToAndroid()
{
string apkLocation = PlayerPrefs.GetString("APK location");
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(apkLocation))
{
apkLocation = EditorUtility.OpenFilePanel(
"Find APK", Environment.CurrentDirectory, "apk");
}
if (string.IsNullOrEmpty(apkLocation) || !File.Exists(apkLocation))
{
UnityEngine.Debug.LogError("Cannot find .apk file.");
return;
}
PlayerPrefs.SetString("APK location", apkLocation);
string adbLocation = EditorPrefs.GetString("AndroidSdkRoot")
+ "/platform-tools/adb";
string command = "install -r " + apkLocation;
print($"{adbLocation} {command}");
ProcessStartInfo info = new ProcessStartInfo
{
FileName = adbLocation,
Arguments = command,
WorkingDirectory = Path.GetDirectoryName(adbLocation),
};
Process.Start(info);
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Can i build for Android OS 2.2 with SDK v4 level r14? 0 Answers
Fog not moving with camera on mobile build 0 Answers
Unity project wont build 0 Answers