Android platform construction

Source: Internet
Author: User
Tags zip extension

I would like to commemorate the efforts of more than a month.

There are several layers between the Android Application Platform and the Linux kernel: 1.c++ framework 2. Java framework. A month ago, I suddenly found that the recording in Android could not be used, whether it was a built-in program or a program downloaded from the Internet, and the debugging kernel found that the parameter passing was incorrect, at first, we thought it was a Linux kernel error. In Linux, aplay can be used for recording, but not for recording software. When we used the recording software, we found that the stream passed was 0, instead of 1. therefore, the device that is enabled is a playback device rather than a capture device. It takes a week to view the Linux source code. Later, I am going to see the interaction between Linux kernel and applications. There is an opencore layer among the discoverers. A bunch of Java and C ++ are hard to understand with my simple C language. I had to give up, and then I learned that there is also the ndk stuff, so I was tempted, because the aplay in Linux can be used, and I just made it into a so library and left it for upper-layer calls. It took two or three days to integrate the eclipse SDK ndk and other Windows android
After the development environment is installed, the so library of ndk is started. The model of the so library is ready, and the following will be filled in.

Next, we use android
Install the development environment.

1. Install eclipse

Next, use the eclipse-java-helios-sr1-win32.zip extension to install jdk-6u23-windows-i586.exe. Sometimes some errors are prompted when you open eclipse. In fact, there may be no JRE folder, copy
Copy the JRE folder in the JDK file under the Java installation file to the eclipse folder.

2. SDK Installation

Download android-sdk_r08-windows.zip and unzip it. In general, you also need to add the path to the environment variable. You can do this without adding it. The difference is that the android virtual machine created in eclipse will be placed in the folder named. android, if not added, it will be in C:/Documents and Settings/user name, the reason for some errors is that the user name is Chinese characters.

3. Add path

My computer-> properties-> advanced-> environment variables-> New

Variable name jre_home variable value C:/program files/Java/jre6

Variable name java_jre_home variable value C:/Program/files/Java/jdk1.6.0 _ 13/JRE

Variable name java_home variable value C:/program files/Java/jdk1.6.0 _ 23

Variable name classpath

Variable value

.; % Java_home %/LIB; % java_home %/lib/tools. jar; % java_home %/lib/DT. jar; % jre_home %/LIB; % jre_home %/lib/RT. jar; % java_jre_home %/LIB; % java_jre_home %/lib/RT. jar

Variable name android_sdk_home variable value D:/Android/source/Android-SDK-Windows

4. Install the ADT plug-in eclipse

Open eclipse and then help-> install new software-> Add
If the name is arbitrary and the location is http://dl-ssl.google.com/android/eclipse, all the way to next. After installation, the android option in file-> New-> Project on the main interface is OK. However, you also need to configure the SDK as the location. In the android field of Windows-> preferences, Click Browse to select the location where the SDK is stored.

5. Install ndk

Download cygwinsetup.zip
And android-ndk-r5-windows.zip android-ndk-1.6_r1-windows.zip, there is no ndk-build. I don't know how to compile this version, so I changed it to a higher version. Install cygwinsetup. Select a website that is relatively close to the next step. When you select which software to download and install, select install, the time is not too long (I spent the next night, hey !!). Then OK. A cygwin icon is displayed on the desktop, which is similar to a terminal. You need to set the ndk path here, because you will use it many times later. Use VI/etc/skel/. bashrc to add

Ndk =/cygdrive/XXX/xxx

Path = $ path: $ ndk

Export ndk

Exit and run source/etc/skel/. bashrc.

$ Ndk should open the folder where ndk is located

6. Install ADB

Download an ADB compressed file, decompress it, and copy the two files to Windows/system32. Run cd c:/Windows/system32 at start-> and then you can use ADB.

7. How to create an android Project

To create an android project, you need to create an AVD. the main interface is windws-> android
SDK and AVD Manager-> New.

Name: avdtest

Target: Android
2.1

Sdcard: 400
MB

After creat AVD. The available avds are listed on the main interface.

8. Create an android
Project

File-> New-> Project-> Android-> android
Project and next,

Project name: Random

Build target: Select Virtual Machine

Application name: Random

The following are all casual. Note that the min SDK version can be 1 ~ 9. For android
2.1, the maximum value is 7. Finish. Click Run on the main interface to run the task.

9. Use ADB

1. Run ADB after entering system32
Shell can enter the running Android system terminal.

2. ADB push writes to the Android system. Generally, read-only filesytem is prompted for the first time. This requires the ADB shell to enter the terminal and enter

Mount-O remount
/Dev/block/mtdblock/system.

If out-memory appears

Enter emulator-AVD in cmd.
Avdname-partition-size 128. Note that if you are prompted that there is no emulator command, you need to set the environment variable. The above is lazy and the following will not work.

3. ADB pull can output things in the Android system.

Such as ADB pull/data/APP/com.examples.apk D:/Android/APK

10. Create the so Library

1. In the project just created, create a folder named JNI and create two files under JNI, one being Android. mk and the other being hello. C.

2. Enter

Local_path: = $ (call my-DIR)

Include $ (clear_vars)

Local_module: = Hello

Local_src_files: = Hello. c

Local_ldlibs: =-LDL
-Llog # Add the system's so file

Local_ldlibs + =-L. /-lasound # Add the local so file-L as the path of the so library. This will accelerate development when someone else's so library is called and header files exist.

Include $ (build_shared_library)

3. Add

# Include <string. h>

# Include
<JNI. h>

# Include
<Dlfcn. h>

# Include
<Android/log. h>

Jint
Java_com_hello_hello_hello (jnienv * ENV, jobject this)

{

Return 12;

}

Note: The preceding function is named com. Hello. The package name is when the android project is created.
Name,

The second hello is the application name, which must be associated with the project. The third hello is the name of the function you intend to call in Java. Modify hello. Java under SRC

Package com. Hello;

 

Import Android. App. activity;

Import Android. OS. Bundle;

Import Android. widget. textview;

 

Public class Hello extends activity {

/**
Called when the activity is first created .*/


@ Override

Public
Void oncreate (bundle savedinstancestate ){


Super. oncreate (savedinstancestate );


// Setcontentview (R. layout. Main );


Textview TV = new textview (this );


TV. settext ("Whether the hello call is successful:" + Hello ());

Setcontentview (TV );

}

Public
Native int Hello ();

Static
{


System. loadlibrary ("hello ");

}

}

If none of the above is correct, click run, and then "Hello call successful: 12" will appear on the android virtual machine ". OK! There is a tip. If the average person doesn't tell him that the file has not been changed, click refrresh. If not, click Project> clean on the main interface.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.