Showing posts with label apg. Show all posts
Showing posts with label apg. Show all posts

Sunday, May 1, 2011

Synchronize Android Phone with Eclipse app development

Trying on 6857_proj with Android 1.6, because my APG is for Android 2.2, but my phone has version 1.6.

Following Setting up a Device for Developement

I have a T-Mobile, which I couldn't find on the list of "USB Vendor IDs", so I used the lsusb to see that I have a "Bus 002 Device 003: ID 0bb4:0c02 High Tech Computer Corp. Dream / ADP1 / G1 Phone (Debug)". So for T-Mobile, it's the same as HTC: SYSFS{idVendor}=="0bb4". (I didn't know T-Mobile is related to HTC)

android-sdk-linux_x86/platform-tools$ ./adb devices
List of devices attached
HT93LLZ01057 device

Then I clicked on "Run" and saw in the counsole:
[2011-05-01 16:30:05 - Apg] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.thialfihar.android.apg/.MainActivity }
[2011-05-01 16:30:20 - 6857_proj] Success!
[2011-05-01 16:30:20 - 6857_proj] Starting activity org.thialfihar.android.apg.MainActivity on device HT93LLZ01057
[2011-05-01 16:30:23 - 6857_proj] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.thialfihar.android.apg/.MainActivity }


Yay! I saw APG on my Phone! :D

========
get ZXing to work:

Pretty easy actually. Just press "Run" and everything is figured out automatically.  Even though my project is for Android 2.3.1 and my phone is 1.6, things worked out! I didn't change anything to the project code! Did NOT add '<application android:debuggable="true" ' in AndroidManifest.xml.

Console message:
[2011-05-02 01:13:07 - Zxing2] ------------------------------
[2011-05-02 01:13:07 - Zxing2] Android Launch!
[2011-05-02 01:13:07 - Zxing2] adb is running normally.
[2011-05-02 01:13:07 - Zxing2] Performing com.google.zxing.client.android.CaptureActivity activity launch
[2011-05-02 01:13:07 - Zxing2] Automatic Target Mode: using device 'HT93LLZ01057'
[2011-05-02 01:13:07 - Zxing2] Uploading Zxing2.apk onto device 'HT93LLZ01057'
[2011-05-02 01:13:08 - Zxing2] Installing Zxing2.apk...
[2011-05-02 01:13:14 - Zxing2] Success!
[2011-05-02 01:13:15 - Zxing2] Starting activity com.google.zxing.client.android.CaptureActivity on device HT93LLZ01057
[2011-05-02 01:13:18 - Zxing2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.google.zxing.client.android/.CaptureActivity }
I did NOT even do the "Run on Android" part of http://code.google.com/p/zxing/wiki/GettingStarted.



Failed attempts at ZXing, I was being too cautious and hit some deadends
I think I should start a new ZXing that is compatible with my 1.6 phone.

If I choose version 1.6, I'll have 2 problems:
1. "R cannot be resolved" because gen > > R.java is not created from Project > clean
2. AndroidManifest.xml gives a "error: No resource identifier found for attribute 'installLocation' in package 'android'" of this line: <manifest xmlns:android="http://schemas.android.com/apk/res/android"

Both of these problems can be resolved if I upgrade the version to 2.3.1 by right clicking on the project name "Properties" and choose 2.3.1.

Might be helpful:
http://stackoverflow.com/questions/4782543/solved-integration-zxing-library-directly-into-my-android-application
"Run on Android" of http://code.google.com/p/zxing/wiki/GettingStarted ... I never had to do it.

Wednesday, April 13, 2011

Setting up Android Privacy Guard + Bouncy Castle from scratch

The APG project suggested using the Bouncy Castle to as a way to learn how to building the APG. Here are some very detailed steps on how to do this from complete scratch, as if it's your first Android project.

The order of getting things working will be:
I. Set up Eclipse with Android Development SDK and ADT emulator
II. Create a new Android Project with APG and Bouncy Castle incoporated in

I. Setting up Android Development on Eclipse, roughly following the Android SDK Installation Guide.
  1. Download Eclipse Classic. (Windows: if it asks, install Java SDK)
  2. Download the Android SDK. (Windows: if it says Java SDK not found when you have installed it, hit "Back" and "Next" :/ ... good job Windows)
  3. Get the Eclipse ADT Plugin for Android Emulator in Eclipse by doing:
    Select Help > Install New Software. Add at top right, Name: "ADT Plugin", Location: "https://dl-ssl.google.com/android/eclipse/", or "http: ..". Okay. Next. Next. Accept. Finish. Restart Now.
  4. Check that this exists: "Window > Android SDK and AVD Manager" If you get this error: "Location of the Android SDK has not been setup in the preferences". You need to do: a) Window > Preferences > Android b) Put in appropriate path file for the "android-sdk-[OS name]" directory in SDK Location, which should come from your "Android SDK" download (If you downloaded the .exe for Windows, download the zip) c) Apply. OK
  5. Install Android Packages on ADT:
    Click on "Window > Android SDK and AVD Manager"
    Click on "Available packages" on the left.
    Check the "Android Repository".
    Press "Install Selected" and "Install"
II. Creating our own Android Virtual Device (AVD) with the APG Project and Bouncy Castle installed on it, roughly following the Android Creating AVDs Guide.
  1. If you don't have SVN, install it. (For Windows, download TortoiseSVN will require restart)
  2. SVN checkout the APG source code. (If you're using TortoiseSVN. Create a folder named "android-privacy-guard-read-only", right click on it, click on "SVN Checkout", and paste the url in.)
  3. Download the Bouncy Castle source code, which should extract to "bc145_reduced_for_apg" folder
  4. Create a new Android project on Eclipse:
    - File > New > Project
    - Click on Android > Android Project. Next. Fill in the rest as the picture shows:
  5. Replace with the APG source code: Navigate to workspace/Apg and replace everything inside there with the files in the Apg source you downloaded in the previous step (so replace src, res, AndroidManifest.xml, etc). 
  6. Add the Bouncy Castle code: copy the bouncycastle2 directory (inside bc145_reduced_for_apg/org) into workspace/Apg/src/org
  7. Run > run: (warning, it'll take a while, a black blank screen doesn't mean it's broken). You should see something like:
  8. Extra: If the size of the emulator is too big. You can resize it by:
    Run > Run Configurations > Target [a tab]
    Write in Additional Emulator Command Line Options: "-scale 0.8" or another number
  9. DONE!

Useless stuff: the long way of doing #4 onwards
  1. Create a new Android project on Eclipse:
    - File > New > Project
    - Click on Android > Android Project. Next.
    - Project name: "6857proj". Target Name: "Android 1.6". Package Name: "org.thialfihar.android.apg". Create Activity: "proj6857". Finish.
  2. Make a new AVD for this project:
    - select "6857proj" form the "Package Explorer" on the left side.
    - Run > Run
    - "Yes" to "No compatible targets were found. Do you wish to add a new AVD?"
    - "New" on top right
    - Name: "6857avd" Target: "Android 1.6". Create AVD
    - Select on the "6857avd" and click "Start". "Launch".
    - Wait for 3+ minutes for the Android emulator to turn on
  3. Add the APG source code into our Android Project:
    - copy all the files and folders inside "android-privacy-guard-read-only -> src -> org -> thialfihar -> android -> apg" into to "[your Eclipse] workspace -> 6857proj -> src -> org -> thialfihar -> android -> apg"
  4. Add the Bouncy Castle code into our Android Project:
    - copy this directory "bc145_reduced_for_apg -> org -> bouncycastle2" into "[your Eclipse] workspace -> 6857proj -> src -> org". So you should end up with "thialfihar" and "bouncycastle2" in the "org" directory.
  5. Put the APG resources into the res of the Android Project:
    - delete the "res" directory in the workspace, and replace it with APG's "res"
  6. Run > run: (warning, it'll take a while, a black blank screen doesn't mean it's broken)
    If you can't run due to errors like "The method xx of type xx must override a superclass", do:
    - Project > Properties
    - Under "Java Compiler," change the compiler compliance level from "1.5" to "1.6". Apply.
    - Now you should be able to run.
  7. Done!
  8. To fix this warning below, you have to replace the "AndroidManifest.xml" with the Apg's version too.
    Sorry!
    The application APG (process org.thialfihar.android.apg) has stopped unexpectedly.
    Please try again.

  9. Extra: If the size of the emulator is too big. You can resize it by:
    Run > Run Configurations > Target [a tab]
    Write in Additional Emulator Command Line Options: "-scale 0.8" or another number

I tried debugging that "stopped unexpectedly" error for a long time. Here are the things I learned:

Finding the base java file: I tried to match up with  the tutorial by grepping for "extends Activity". I found it in the org/thialfihar.android.apg/BaseActivity.java file, which also has onCreate().

Debugger can be useless: I tried placing a break in the first line of the main function in the basefile. When I ran Run > Debug History and started stepping through the files, a lot of Source not found came up. It was misleading, because when I tried breaking in similar fashions in a working "Hello Android" project, the same "Source not found" errors came up.

LogCat is supposed to help debugging, but since I had no idea what the code was about, it wasn't helpful for me.