User Tools

Site Tools


proton:android_setup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
proton:android_setup [2011/09/16 04:55]
seth
proton:android_setup [2017/05/22 08:33] (current)
seth
Line 1: Line 1:
-**NOTE:** If you have any problems packing Android things with ant, check [[http://​www.rtsoft.com/​forums/​showthread.php?​3958-Yet-another-Android-problem|this thread]] for the solution. It looks like the latest NDK changed something.+Before going in to compilation details ​check [[proton:android_projects|what you need to know about the Android ​projects in general]].
  
 ====Compiling for Android from Windows==== ====Compiling for Android from Windows====
 +
 +** NOTE: ** 5/​22/​2017: ​ I updated to the latest NDK (r14b 64bit) and it works fine, C++11 now supported
 +
 +**NOTE:​** ​ 6/19/2013 - Proton has been updated to work with the latest Android platform tools (17), SDK tools (22.0.1) and the latest NDK. (r8e)  If your old proton project won't compile, steal the android/​build.xml from a proton example and replace your old one.  (And edit the top as need..)
 +
 Originally the Android platform was crippled by requiring all "​app"​ code to be written in Java. Originally the Android platform was crippled by requiring all "​app"​ code to be written in Java.
  
Line 8: Line 13:
   * Native ARM machine code is faster than using Java   * Native ARM machine code is faster than using Java
   * The ability to use millions of lines of existing legacy C++ code   * The ability to use millions of lines of existing legacy C++ code
-  * Can use boost and stl+  * Can use boost and stl (since r5 I think..)
   * Can write an Android game without writing a single line of Java   * Can write an Android game without writing a single line of Java
   * Can debug your app in MSVC or Xcode   * Can debug your app in MSVC or Xcode
Line 17: Line 22:
  
 The C++ "​glue"​ code for Android is located in /​shared/​android and the .Java parts are in /​shared/​android/​src. ​ These are shared between all applications so be careful if you touch them. The C++ "​glue"​ code for Android is located in /​shared/​android and the .Java parts are in /​shared/​android/​src. ​ These are shared between all applications so be careful if you touch them.
 +
 +** Side Note **: There is actually an even newer way to do NDK now - something called a NativeActivity where you can use 100% C++.  Except you can't, because things like IAP and Tapjoy integration would still be in Java so I assume more ugly bridging would be required.. also it requires Android 2.3+, but I plan to do an android target supporting this eventually, especially since it seems to be the only way to fully support the xperia play analog sticks. -Seth
  
 ====Prerequisites==== ====Prerequisites====
-Before attempting ​moving ​on, you really should already have done this:+Before attempting ​to move on, you really should already have done this:
  
   * Read the [[proton:​win_setup|Compiling RTBareBones for Windows tutorial]]   * Read the [[proton:​win_setup|Compiling RTBareBones for Windows tutorial]]
Line 25: Line 32:
  
 NOTE (MK): RTSimpleApp,​ you need to do the "​Building resources"​ step. Otherwise, the app will crash/exit right away, and you'll get the "​Can'​t load font 1" error mentioned. NOTE (MK): RTSimpleApp,​ you need to do the "​Building resources"​ step. Otherwise, the app will crash/exit right away, and you'll get the "​Can'​t load font 1" error mentioned.
-====Section 1: Setting up your Windows computer to compile for Android==== 
-Get ready to do a lot of downloading and installing. ​ Android is the most complicated setup to get going so far. 
  
-This is going to take a while.+====Section 1: Setting up your Windows computer ​to compile for Android==== 
 +Get ready to do some downloading and installing!
  
-  * Install the [[http://​developer.android.com/​sdk/​index.html|Android SDK]] - use the Windows exe version so it will also prompt you to install ​the Java SE JDK which will be needed as well. +Important note For all this stuff, try to choose a custom ​install path WITHOUT spaces in it.  ​There, I just saved you like 40 minutes of diagnosing vague errors that will happen later No charge, friend!
-  * Add **C:​\Program Files (x86)\Android\android-sdk\platform-tools** to your windows ​path +
-  * Add **C:​\Program Files (x86)\Android\android-sdk\tools** to your path +
-  * [[http://​cygwin.com/​install.html|Install Cygwin]] - you run the setup.exe to create/​update an install, ​it's very simple.  ​During the part where it lets you choose what additional parts to install, I strongly suggest selecting the entire dev subtree to be safe.+
  
 +  * Install the [[http://​developer.android.com/​sdk/​index.html|Android SDK]] - use the Windows exe version so it will also prompt you to install the Java SE JDK which will be needed as well. NOTE - you'll need to install the 32bit version of the Java JDK, NOT the 64 bit, since the android SDK install process won't recognize the 64 bit version. Also note, the advice about using a custom install path applies as much for the Java JDK as it does for everything else. If you install Java to Program Files, ANT will complain about this later (since Ant sits on top of Java).
 +  * Add **C:​\whatever\android-sdk\platform-tools** to your windows path 
 +  * Add **C:​\whatever\android-sdk\tools** to your windows path
  
-If you type "​android"​ from the DOS prompt it will bring up the Android SDK and AVD Manager. ​ This is where you create AVDs (basically, emulator profiles, if you want to use the emulator) and can install optional libraries.+If you type "​android"​ from the DOS prompt it will bring up the Android SDK and AVD Manager. ​ This is where you create AVDs (basically, emulator profiles, if you want to use the emulator) and can install optional libraries.  It also shows you when you can update your platform tools.
  
 Here is how I setup my AVD (note my naming format.. helps later to remember which AVD is which version) Here is how I setup my AVD (note my naming format.. helps later to remember which AVD is which version)
Line 42: Line 48:
 {{:​proton:​avd_creation.png?​100|}} {{:​proton:​avd_creation.png?​100|}}
  
 +Having said that, the truth is I never use the AVD/​emulator stuff, it's too slow and useless.
  
 Make sure you install "USB Driver package, revision X", your phone probably needs this.  Also, "​Market licensing package, revision X" is needed. Make sure you install "USB Driver package, revision X", your phone probably needs this.  Also, "​Market licensing package, revision X" is needed.
Line 49: Line 56:
 **Another note**: The emulator refused to start until I edited the path to be a dos 8.3 format. ​ (Ie, C:​\PROGRA~2\Android\android-sdk\tools instead of C:\Program Files (x86)\Android\android-sdk\tools - you can use dir /x to get the exact name to use) **Another note**: The emulator refused to start until I edited the path to be a dos 8.3 format. ​ (Ie, C:​\PROGRA~2\Android\android-sdk\tools instead of C:\Program Files (x86)\Android\android-sdk\tools - you can use dir /x to get the exact name to use)
  
-You want to test on your real phone, right?+You want to test on your real device(s), right?
  
-Setup your Android ​phone like this:+Driver links for your device: 
 + 
 +  * For Nexus One and Nexus S, download them from the Android SDK and AVD Manager, then they will be in /​android-sdk/​extra/​google/​usb_driver. 
 +  * [[http://​www.motorola.com/​Support/​US-EN/​Support-Homepage/​Software_and_Drivers/​USB-and-PC-Charging-Drivers|Xoom and Motorola drivers]] 
 +  * [[http://​developer.android.com/​sdk/​oem-usb.html|Other drivers]] 
 + 
 +Setup your Android ​device ​like this:
  
   * In Settings->​Applications enable "​Unknown sources"​. Otherwise you can't test your apps.   * In Settings->​Applications enable "​Unknown sources"​. Otherwise you can't test your apps.
   * In Settings->​Applications->​Development enable "USB debugging"​   * In Settings->​Applications->​Development enable "USB debugging"​
-  * After plugging in your phone, in the Win device manager it will probably say "no drivers installed"​ - click update driver and locate the USB drivers you downloaded above using the Android SDK and AVD Manager. (Probably in Program Files (x86)/​Android/​android-sdk/​extras/​google/​usb_driver) ​ If it's not a Nexus One or Nexus S, you may need one of [[http://​developer.android.com/​sdk/​oem-usb.html|these drivers]] instead. +  * After plugging in your phone, in the Win device manager it will probably say "no drivers installed"​ - click update driver and install them 
-  * Typing "abd devices"​ should show your plugged in phone as a device now.  If so, congrats, you got this far!+  * Typing "adb devices"​ should show your plugged in phone as a device now.  If so, congrats, you got this far!
  
-Ok.  In theory, you're now setup for building a standard Android app and running it in the emulator or on your phone. 
  
-You don't absolutely have tobut I'd recommend installing [[http://​www.eclipse.org/​downloads/​|Eclipse]] (get Eclipse IDE for Java Developers) and building a "hello world" ​app to test everything thus far.  [[http://​www.vogella.de/​articles/​Android/​article.html#​installation|Nice tutorial ​on doing that is here]].+Ok.  In theoryyou're now setup for building a standard Android ​app and running it in the emulator or on your device(The emulator truly emulates, it can use the same file)
  
-Android is complex and I don'​t ​really think p+ can shield you from its intricacies. ​ You still need to know how to create an AVD emulatorunderstand what a .manifest is and know what obscure error messages like "Committing suicide to kill the zombie!" ​mean.+You don'​t ​absolutely have to, but if you run into any snags in the install later, come back to this point and try installing [[http://​www.eclipse.org/​downloads/​|Eclipse]] (get Eclipse IDE for Java Developers) ​and building a "hello world" ​app to test everything thus far.  [[http://​www.vogella.de/​articles/​Android/​article.html#​installation|Nice tutorial on doing that is here]]. ​ Actually, don't, waste of time probably.
  
-You should probably spend a few days of hacking around with hello world apps to get feel for it before attempting ​to use Proton SDK with it.+Android is complex and I don't really think p+ can shield you from its intricacies.  ​You still need to know what .manifest is and you'll be seeing obscure error messages like "​Committing suicide ​to kill the zombie!"​. ​ Well, bad example because I still don't know what that error message really means.
  
-====Section 2: Setting ​up the NDK and compiling RTBareBones====+====Section 2: Downloading and setting ​up the NDK and compiling RTBareBones====
  
-Ok, your hairs have magically turned white and mostly fallen out, but you've finally got your hello world app on your device. +Ok, typing adb from the dos prompt shows your device ​and you seem good to go to the next step.
- +
-You are now ready to move to the next step.+
  
 First, mentally throw away Eclipse if you were using it for testing - you'll never need it again. First, mentally throw away Eclipse if you were using it for testing - you'll never need it again.
  
-  * Install [[http://​ant.apache.org/​bindownload.cgi|Ant]],​ grab the latest .zip (v1.8.at this time) and unzip it to somewhere. +  * Install [[http://​ant.apache.org/​bindownload.cgi|Ant]],​ grab the latest .zip (v1.8.at this time) and unzip it to somewhere. 
-  * Add the ant directory to your windows path.  Verify it's working by typing "​ant"​ in a dos prompt, it should do something other than "bad command or file error"​. +  * Add the ant directory to your windows path.  Verify it's working by typing "​ant"​ in a dos prompt, it should do something other than "bad command or file error"​. ​NOTE - the path you add needs to go to the Binaries directory, not just the root ant dir - E.g. C:​\Android\apache-ant-1.8.4\bin 
-  * Download the [[http://​developer.android.com/​sdk/​ndk/​index.html|Android NDK]] and unzip it somewhere.+  * Download the [[http://​developer.android.com/​sdk/​ndk/​index.html|Android NDK]] and unzip it somewhere.  Again, put it somewhere with no spaces in the filenames if possible. ​ (Not "​Program Files"​!) 
 +  * Make sure that the environmental variable ANT_HOME exists and is set to your ant path.  (ie, c:​\pro\ant) 
 + 
 +**Note**: The NDK version should be r8 (latest at the time this was written) or later
   ​   ​
-Ant is command line utility that will do the Android packaging for us after the .so binary is built.  Cygwin lets us run linux-style stuff on Windows.+Ant is command line utility that will do the Android packaging for us after the .so binary is built.
  
-Annoying ​stuff you have to do:+More annoying ​stuff you have to do:
  
-  * Add a Windows environmental var CYGWIN_DIR to your base cygwin directory. 
   * Add your android ndk dir to the windows path   * Add your android ndk dir to the windows path
-  * Edit RTBareBones/​android/​app_info_setup.bat and set the variables up if different, note that you can set the emulator AVD name you wish to use 
-  * Edit RTBareBones/​android/​local.properties and set the path to your android-sdk dir. (used by ant) 
-  * Edit RTBareBones/​android/​build.sh and set the path.  Instead of "/​cygdrive/​o/​projects/​proton/​rtbarebones/​android"​ it should be "/​cygdrive/​c/​proton/​rtbarebones/​android"​ or wherever you put proton. ​ Also see where you have to change it a bit below. 
- 
-Phew!  I could probably find ways to reduce the hand edits needed above but meh.  Good enough for now.  Tricky hacks like reading from windows environmental vars from inside cygwin would make it harder to build from linux or mac later, don't want that either. 
  
 ====Finally,​ the compile!==== ====Finally,​ the compile!====
Line 96: Line 103:
 From file explorer, double click /​RTBareBones/​android/​build.bat From file explorer, double click /​RTBareBones/​android/​build.bat
  
-You should see bunch of weird warnings like "this precompiled header message should show up once" showing up forty times This is all perfectly normal Trust me.+After lengthy C++ compile process, it then compiles the Java pieces in one second, then puts it on the active device, as long as you only have one plugged inThe .apk it makes is located in /​RTBareBones/​android/​bin in case you want to give it to someone else to test with.
  
-After a lengthy C++ compile process, ​it then compiles the Java pieces ​in one secondthen slowly puts it on  the Emulator and your real phone if it can.  ​The .apk it makes is located in /​RTBareBones/​android/​bin in case you want to give it to someone else to test with.+Tips: 
 +  * build.bat uses InstallOnDefaultPhone.bat which installs ​it to whatever device is plugged ​in, as long as only one device exists, it works. 
 +  * If any headers change, ​you may want to use Clean.bat ​to make sure make notices that they changed correctly. 
 +  * Use buildRelease.bat ​to make the final, signed version to upload to the android store It also produces an unsigned version that is useful sometimes. (Amazon'​s store wants it that way, for instance)
  
-Run ViewLog.bat to see the debug output ​from the emulatoror ViewLogPhone.bat to see the debug output from your phone.+Run ViewLogDefaultPhone.bat to see the debug output. (As long as only one device is plugged in/active, it will work, be it the emulator or a real device)
  
 ====Customize the .mak==== ====Customize the .mak====
-If you need to add remove source files to the project, manually edit RTBareBones/​jni/​Android.mk.+If you need to add/remove source files to the project, manually edit RTBareBones/android/​jni/​Android.mk.
  
 Also, if you're having trouble, it's a good idea to enable debug mode compiling. ​ To do that, change: Also, if you're having trouble, it's a good idea to enable debug mode compiling. ​ To do that, change:
Line 130: Line 140:
 Don't forget to change it back later. Don't forget to change it back later.
  
-====Enabling the Android Market Licensing Verification Library==== +Note:  The above may be outdated with some projects ​and instead of LOCAL_CFLAGS/LOCAL_CPPFLAGS it's actually SHARED_FLAGS or MY_FLAGS ​to avoid duplicationWhatever, it's simple ​to see/​edit ​stuff in there.
-If you want to sell your App in the Android market, you should use [[http://​developer.android.com/​guide/​publishing/​licensing.html|LVL]]. +
- +
-It's actually already implemented in Proton SDK, take a look at the only .Java file in RTBareBones,​ located in RTBareBones/​android/​src/​com/​rtsoft/​rtbarebones +
- +
-<code java> +
-//This is the only app-specific java file for the android project. ​ ​The ​real work is done in +
-//​shared/​android/​src/​rtsoft/​shared/​SharedActivity.java. ​ When editing that, be careful, as it is used +
-//by all Proton ​projects+
- +
-//​Thanks ​to Phil Hassey for his help and code +
- +
-package com.rtsoft.rtbarebones;​ +
-import com.rtsoft.shared.SharedActivity;​ +
-import android.os.Bundle;​ +
- +
-public class Main extends SharedActivity +
-+
- @Override +
-    protected void onCreate(Bundle savedInstanceState)  +
-+
- //EDIT THESE TO MATCH YOUR PROJECT NAME +
- BASE64_PUBLIC_KEY = "uh, it would go here if you had one and wanted ​to use the google licensing ​stuff"; +
- PackageName= "​com.rtsoft.rtbarebones";​ +
- dllname= "​rtbarebones";​ +
- securityEnabled = false;  +
-       ​super.onCreate(savedInstanceState);​ +
-    } +
-+
-</​code>​ +
- +
-You would just need to enter your public key (The Google developer console gives this to you after you sign up) and change "​securityEnabled"​ to true.+
  
-====Final thoughts==== +The only app specific .java file is located in /​android/​src/​Main.java. ​ It has some options ​for enabling security, Tapjoy, Hooked, and such.
-That's about it for getting the samples running.+
  
-Use the same process to compile RTSimpleApp.+====Final thoughts and tips ==== 
 +That's about it for getting ​the samples running on Android.
  
-Want to clone one of the example apps to be the starting place of a new app? Then read the tutorial on [[:​proton_vsrename|how to create a new project by copying from a Proton sample app]].+Use the same process ​to compile RTSimpleApp and the others.
  
 +  * Want to clone one of the example apps to be the starting place of a new app? Then read the tutorial on [[:​proton_vsrename|how to create a new project by copying from a Proton sample app]].
 +  * Want to compile faster? ​ Change call ndk-build in build_prepare.bat to call ndk-build -j8 (or lower than eight if you don't have 8 threads on your multicore cpu)
proton/android_setup.1316148948.txt.gz · Last modified: 2011/09/16 04:55 by seth