Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by cregox · Sep 30, 2011 at 01:45 PM · buildmobilecompilingandroid2.2

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Oct 03, 2011 at 03:02 PM 0
Share

Now what would make this practially perfect would be a way to script this into unity! :D

avatar image
3

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);
  }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Structed · Jul 09, 2014 at 02:01 PM 0
Share

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

avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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);
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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

Ragdoll : slight pause before it starts? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges