This is the simplest Android project I've tried in a Windows environment, just with Notepad and the command line.
Environment Preparation
The development environment requires the Java SDK (official website download), the Android SDK (official website download).
First install the Java SDK, and then extract the Android SDK to any directory (it is recommended to extract to a packing directory to facilitate subsequent command input).
Then you need to download the Android SDK. Open the SDK Manager in the directory you just unzipped, tick the SDK that needs to be installed platform Click the Install package to download the installation.
Project creation and code writing
Create a new directory anywhere, save the project, and create a new SRC directory to hold the source files. Because Java has the concept of a package, so after entering the SRC directory, according to the level of the package name, set up the corresponding directory, and then create a new Java source program files, such as:
1 Packagetest.android;2 3 Importandroid.app.Activity;4 ImportAndroid.os.Bundle;5 ImportAndroid.app.AlertDialog;6 7 Public classMiniextendsActivity {8 Public voidonCreate (Bundle savedinstancestate) {9 Super. OnCreate (savedinstancestate);Ten NewAlertdialog.builder ( This). Setmessage ("It works.")). Show (); One } A}
Save the file as Mini.java
Go back to the project root and create another file, save as Androidmanifest.xml, with the following:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Test.android">3 <Application>4 <ActivityAndroid:name=". Mini ">5 <Intent-filter>6 <ActionAndroid:name= "Android.intent.action.MAIN" />7 <categoryAndroid:name= "Android.intent.category.LAUNCHER" />8 </Intent-filter>9 </Activity>Ten </Application> One </Manifest>
You can also download the demo project from here.
Well, the project has been completed, the following into the compilation of packaging links.
Compile Package
Open the command line first, enter Javac-version, and if the Java version number is not displayed, add the Java SDK's Bin directory to the PATH environment variable.
Switch the current directory to the root of the project, and then create a new two directory
1 mkdir bin 2 mkdir bin\classes
Because the resource file is not used, the first step is to compile the Java source file directly.
1 javac-encoding utf-8-source 1.7-target 1.7-bootclasspath \android\android-sdk-windows\platforms\ android-23\android.jar-d bin\classes Src\test\android\mini.java
Package compiled files in DEX format
1 D:\Android\android-sdk-windows\build-tools\23.0.3\dx.bat--dex--output=bin\classes.dex bin\classes
Package A resource file
1 D:\Android\android-sdk-windows\build-tools\23.0.3\aapt.exe package-f-M androidmanifest.xml-i \android\sdk\ Platforms\android-19\android.jar-f Bin\mini
Package all files into an apk with Apkbuilder
1 D:\Android\android-sdk-windows\tools\apkbuilder.bat \workspace\test\android\minimum\mini.apk-v-u-z D:\workspace \test\android\minimum\bin\mini-f D:\workspace\test\android\minimum\bin\classes.dex
The Apkbuilder.bat is not available in the higher version of the Java SDK, where the file content is pasted and you can create one yourself:
1 @echo off2REM Copyright (C) -The Android Open Source Project3 REM4REM Licensed under the Apache License, Version2.0(The"License");5REM If not use thisfileExceptinchcompliance with the License.6 rem Obtain a copy of the License at7 REM8REM http://www.apache.org/licenses/LICENSE-2.09 REMTenREM unless required by applicable or agreed toinchwriting, Software OneREM distributed under the License is distributed in an" as is"BASIS, A REM without warranties or CONDITIONS of any KIND, either express or implied. -REM See the License forThe specific language governing permissions and - REM Limitations under the License. the -REM Don'T Modify the caller's Environment - setlocal - + rem Set up prog to is the path of this script, including following symlinks, -REM and set up Progdir to be the fully-qualified pathname of its directory. +Set prog=%~F0 A at REM Change current directory and drive to where the script was, to avoid - REM Issues with directories containing whitespaces. -CD/D%~dp0 - -REM Check we have a valid Java.exeinchThe path. -Set java_exe= in Call Lib\find_java.bat - ifNot defined Java_exe goto:eof to +Set jarfile=Sdklib.jar -Set frameworkdir= the * ifexist%frameworkdir%%jarfile%Goto Jarfileok $Set frameworkdir=LibPanax Notoginseng - ifexist%frameworkdir%%jarfile%Goto Jarfileok theSet frameworkdir=.. \framework + A : Jarfileok the +Set jarpath=%frameworkdir%%jarfile% - $Call%java_exe%-classpath%jarpath% com.android.sdklib.build.ApkBuilderMain%*
Generate Signature File
1 Keytool-genkey-alias my.keystore-keyalg rsa-validity 20000-keypass 123456-storepass 123456-keystore my.keystore
When the signature file is generated, the prompt for the name unit can be directly entered and ignored, and finally enter Y to confirm.
Signing the APK file
1 jarsigner-verbose-keystore my.keystore-keypass 123456-storepass 123456-signedjar mini_signed.apk mini.apk My.keysto Re
The final apk file is generated and can be installed on the phone.
The simplest Android project