Android + Eclipse + PhoneGap 2.9.0 安卓最新環境配置,部分資料整合網上資料,已成功安裝.


前言:最近心血來潮做了一個廣州花都論壇,打算推出本地服務o2o應用。快速開發手機應用,最后選擇了phonegap,這里我只是講述我安裝的過程,僅供大家參考。

我開發的一個模型http://www.w30.cn 可以看下。看看有多差。

如果有什么問題也可以到小組留言,可以的話,貢獻一個ip:)

phonegap小組 http://www.w30.cn/group/1

如果有什么問題也可以加入我們的QQ群:64674997

ok 不多說了,下面是我的安裝過程

環境搭建首先要去下載一些安裝包:

(下載前注意一下,電腦是32位還是64位的請注意選擇安裝包)

java環境的JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html

我安裝的是64位,下載自己系統環境需要的版本,下載后默認安裝,完成后 在 開始 - 輸入cmd- 輸入java 顯示出java版本信息表示安裝已經成功

 

接着安裝

一、下載安裝ADT。http://developer.android.com/sdk/index.html

 

二、Android的壓縮包為:adt-bundle-windows-x86_64。

  解壓后,進入eclipse目錄,運行eclipse.exe。

1)先更新Android包:選擇 Window -------->Android SDK Manager

全部勾選后,點擊 Install packages,將所有包全部打上。

 

 

2)配置AVD環境

配置該環境有兩種方法:

1、使用界面進行配置,進入方式如圖所示:

 

打開之后,如圖所示,點擊New新建。

 

三、配置PhoneGap(這個比較麻煩)

1)先新建一個新的工程。

具體詳細可以查看:

http://developer.android.com/intl/zh-CN/training/basics/firstapp/creating-project.html

打開ADT,新建一個安卓應用項目

輸入名稱,然后下一步

可以選擇下項目位置,我的是默認的。

這里可以選擇圖標。

選擇第一個

這個時候,一個安卓項目就建好了。

phonegap下載地址:http://phonegap.com/install/

將PhoneGap目錄下的android目錄下的jar文件拷貝到項目的libs目錄下

 

將xml目錄拷貝到項目的res目錄下

 

在assetc目錄下,建立一個www目錄,下面放html內容。為了偷懶,我把phonegap例子里面的內容拷貝過來了。

 

修改Java代碼:

package com.myexample.helloworld;

import android.os.Bundle;
import org.apache.cordova.*;

public class MainActivity extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        //super.loadUrl(Config.getStartUrl());
        super.loadUrl("file:///android_asset/www/index.html")
    }
}

/*
 * 下面是adt生成的代碼,注釋掉
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}*/

 修改一下項目根目錄下的AndroidManifest.xml和res/xml目錄下的config.xml文件
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.

-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myexample.helloworld"
    android:hardwareAccelerated="true"
    android:versionCode="1"
    android:versionName="1.0"
    android:windowSoftInputMode="adjustPan" >

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <application
        android:debuggable="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.myexample.helloworld.MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

</manifest>

 config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-->
<widget
    id="com.myexample.helloworld"
    version="2.0.0"
    xmlns="http://www.w3.org/ns/widgets" >

    <name>
helloworld
    </name>

    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>

    <author
        email="dev@cordova.apache.org"
        href="http://cordova.io" >
        Apache Cordova Team
    </author>

    <access origin="*" />

    <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
    <content src="index.html" />

    <preference
        name="loglevel"
        value="DEBUG" />
    <!--
      <preference name="splashscreen" value="resourceName" />
      <preference name="backgroundColor" value="0xFFF" />
      <preference name="loadUrlTimeoutValue" value="20000" />
      <preference name="InAppBrowserStorageEnabled" value="true" />
      <preference name="disallowOverscroll" value="true" />
    -->

    <feature name="App" >
        <param
            name="android-package"
            value="org.apache.cordova.App" />
    </feature>
    <feature name="Geolocation" >
        <param
            name="android-package"
            value="org.apache.cordova.GeoBroker" />
    </feature>
    <feature name="Device" >
        <param
            name="android-package"
            value="org.apache.cordova.Device" />
    </feature>
    <feature name="Accelerometer" >
        <param
            name="android-package"
            value="org.apache.cordova.AccelListener" />
    </feature>
    <feature name="Compass" >
        <param
            name="android-package"
            value="org.apache.cordova.CompassListener" />
    </feature>
    <feature name="Media" >
        <param
            name="android-package"
            value="org.apache.cordova.AudioHandler" />
    </feature>
    <feature name="Camera" >
        <param
            name="android-package"
            value="org.apache.cordova.CameraLauncher" />
    </feature>
    <feature name="Contacts" >
        <param
            name="android-package"
            value="org.apache.cordova.ContactManager" />
    </feature>
    <feature name="File" >
        <param
            name="android-package"
            value="org.apache.cordova.FileUtils" />
    </feature>
    <feature name="NetworkStatus" >
        <param
            name="android-package"
            value="org.apache.cordova.NetworkManager" />
    </feature>
    <feature name="Notification" >
        <param
            name="android-package"
            value="org.apache.cordova.Notification" />
    </feature>
    <feature name="Storage" >
        <param
            name="android-package"
            value="org.apache.cordova.Storage" />
    </feature>
    <feature name="FileTransfer" >
        <param
            name="android-package"
            value="org.apache.cordova.FileTransfer" />
    </feature>
    <feature name="Capture" >
        <param
            name="android-package"
            value="org.apache.cordova.Capture" />
    </feature>
    <feature name="Battery" >
        <param
            name="android-package"
            value="org.apache.cordova.BatteryListener" />
    </feature>
    <feature name="SplashScreen" >
        <param
            name="android-package"
            value="org.apache.cordova.SplashScreen" />
    </feature>
    <feature name="Echo" >
        <param
            name="android-package"
            value="org.apache.cordova.Echo" />
    </feature>
    <feature name="Globalization" >
        <param
            name="android-package"
            value="org.apache.cordova.Globalization" />
    </feature>
    <feature name="InAppBrowser" >
        <param
            name="android-package"
            value="org.apache.cordova.InAppBrowser" />
    </feature>
    <!-- Deprecated plugins element. Remove in 3.0 -->
    <plugins>
    </plugins>

</widget>

 然后,就可以運行了

 

 

PhoneGap的官方方法不是這樣的,是用命令行生成默認包的。但是要裝好幾個東西。具體可以看PhoneGap包里面的readme文檔。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM