User:Joel Reymont/Android Notes: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 53: Line 53:
</pre>
</pre>


3. make sdk
3. lunch sdk-eng && make sdk


You should see something like this if everything goes well
You should see something like this if everything goes well
Line 108: Line 108:
cd /Volumes/android/mydroid
cd /Volumes/android/mydroid
. ./build/envsetup.sh
. ./build/envsetup.sh
lunch generic-eng && emulator
emulator
</pre>
</pre>



Revision as of 13:46, 9 October 2009

Intro

This page collects my notes on porting Firefox to Android.

Current status

October 7, 2009

Previous statuses

Android Notes

Drawing and input from native code

Via Jack Palevich...

Input is done by subclassing a view, and override the various input methods. Make sure your view can get focus, using setFocusableInTouchMode(true); 
Otherwise you won't get input events. You could use any View class as your base class, but I suggest that you subclass GLSurfaceView because that makes it easier to use OpenGL graphics for drawing.

Probably the fastest way to get output from native code is done using OpenGL ES, which is newly available in NDK 1.6. Create a texture the size of the 
screen ( it has to be a power of two on each side, so 512 x 256 if your screen is 320 x 240.) Then update the texture and render it to the screen as a screen aligned quad.

For native OpenGL ES APIs the drawing surface is implicit in the thread. For Quake, GLSurfaceView's rendering thread sets up the context and calls the QuakeView's Renderer, which calls the native code, which makes the native GL calls.

Because the context is implicit in the thread, there's nothing that needs to be passed between Java and native code.

The downside of this approach is that you can't wrap the native GL calls as easily as you can wrap the JSR 239 Java OpenGL APIs. It's sometimes useful to wrap the GL APIs to keep track of the matrix stack, or log debugging messages, or check for error messages.

Building Android on Snow Leopard

1. Get the sources.

2. Apply these changes

cd system/core && git pull git://android.git.kernel.org/platform/system/core refs/changes/45/11845/2 && cd ../..
cd external/qemu && git pull git://android.git.kernel.org/platform/external/qemu refs/changes/46/11846/2 && cd ../..
cd prebuilt && git pull git://android.git.kernel.org/platform/prebuilt refs/changes/14/12014/1 && cd ..
cd prebuilt && git pull git://android.git.kernel.org/platform/prebuilt refs/changes/75/12075/1 && cd ..
cd build && git pull git://android.git.kernel.org/platform/build refs/changes/74/12074/1 && cd ..
cd build && git pull git://android.git.kernel.org/platform/build refs/changes/93/12093/1 && cd .. 

The following almost works but resets the head each time. Both of the last two changes are needed but the Java one gets written over by the very last change. Also, changes downloaded this way get blown away on repo sync.

repo download platform/system/core 11845/2
repo download platform/external/qemu 11846/2
repo download platform/prebuilt 12014/1
repo download platform/prebuilt 12075/1
repo download platform/build 12074/1
repo download platform/build 12093/1

3. lunch sdk-eng && make sdk

You should see something like this if everything goes well

ls out/host/darwin-x86/sdk/
android-sdk_eng.joelr_mac-x86		sdk_deps.mk
android-sdk_eng.joelr_mac-x86.zip

One more step is needed

export PATH=$PATH:`pwd`/out/host/darwin-x86/sdk/android-sdk_eng.joelr_mac-x86/tools/
pushd prebuilt && ln -s darwin-x86 darwin-x86_64 && popd
pushd out/host/darwin-x86/sdk/android-sdk_eng.joelr_mac-x86/tools/lib
ln -s x86 x86_64 && popd

Verify that everything works

android list targets

Available Android targets:
id: 1
     Name: Android 1.6
     Type: Platform
     API level: 4
     Revision: 1
     Skins: HVGA (default), QVGA, WVGA800, WVGA854

and

     
android list avd

Available Android Virtual Devices:

4. You are set and you can now run the emulator, e.g.

export AND_HOME=/Volumes/android/mydroid
export AND_SDK=$AND_HOME/out/host/darwin-x86/sdk/android-sdk_eng.joelr_mac-x86
export AND_BIN=$AND_SDK/tools
export AND_IMG=$AND_SDK/platforms/android-1.6/images
export AND_KERNEL=$AND_IMG/kernel-qemu
export PATH=$PATH:$AND_BIN

hdiutil attach ~/work/android/android.dmg -mountpoint /Volumes/android
cd /Volumes/android/mydroid
. ./build/envsetup.sh
emulator

You should see home screen in a minute or less.

You can also run the emulator in verbose mode if you want to troubleshoot or just see lots of interesting output, e.g.

emulator -verbose -logcat "*:v"

emulator: found Android build root: /Volumes/android/mydroid
emulator: found Android build out:  /Volumes/android/mydroid/out/target/product/generic
emulator:     locking user data image at /Volumes/android/mydroid/out/target/product/generic/userdata-qemu.img
emulator: selecting default skin name 'HVGA'
emulator: autoconfig: -skin HVGA
emulator: autoconfig: -skindir /Volumes/android/mydroid/development/emulator/skins
emulator: keyset loaded from: /Users/joelr/.android/default.keyset
emulator: trying to load skin file '/Volumes/android/mydroid/development/emulator/skins/HVGA/layout'
emulator: skin network speed: 'full'
emulator: skin network delay: 'none'
emulator: no SD Card image at '/Volumes/android/mydroid/out/target/product/generic/sdcard.img'
emulator: registered 'boot-properties' qemud service
emulator: registered 'boot-properties' qemud service
emulator: Adding boot property: 'qemu.sf.lcd_density' = '160'
...

Vlad's Android Notes

Can be found here.