2

我正在尝试使用 Eclipse 和 PhoneGap 构建一个 Android 应用程序,但我不断收到错误消息

[2013-05-21 17:47:39 - PhoneGapTest] Project has no target set. Edit the project properties to set one.
[2013-05-21 17:47:50 - PhoneGapTest] Parser exception for /PhoneGapTest/AndroidManifest.xml: Premature end of file.

...在打开项目时。我打开项目属性并设置目标,但 xml 异常仍然存在。我已经清理并构建了项目,卸载并重新下载了我的 android SDK 并更新了我的 ADT,但都无济于事。AndroidManifest.xml的。在错误控制台中,我有这个......

Archive for required library: 'E:/AndroidProjects/workspace/PhoneGapTest/libs/cordova-2.7.0.jar' in project 'PhoneGapTest' cannot be read or is not a valid ZIP file    Build Path Problem

啊,现在我看到cordova jar项目中的 in 完全是空的。但这必须每次都发生,因为我已经尝试create在终端上使用 PhoneGap 命令重建这个项目 100 次。为什么会这样?

编辑 - 好的,现在我cordova jar通过从下载中复制和粘贴直接添加,但是现在当我尝试从现有源创建 android 项目时没有任何反应。该文件夹甚至没有出现在包资源管理器中。那么为什么PhoneGap命令行创建工具会创建一个我什至无法打开的AndroidManifest.xml空虚的项目呢?cordova jar

编辑-好的,我认为至少部分问题是我在一些环境变量中使用了空格,特别是Program Files. 我现在已经用%PROGRAMFILES%变量处理了这个问题,PhoneGap 生成的目录现在有一个有效的 cordova jar 和AndroidManifest.xml4KB 的文件。下面是AndroidManifest.xml使用PhoneGap创建命令行工具后的内容...

<?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" android:windowSoftInputMode="adjustPan"
      package="com.gsu.PhoneGapTest" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="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:icon="@drawable/icon" android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:debuggable="true">
        <activity android:name="PhoneGapTest" android:label="@string/app_name"
                android:theme="@android:style/Theme.Black.NoTitleBar"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <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> 

...而cordova jar 应该是251 KB。现在这是奇怪的部分。在我使用现有代码创建 android 项目后,就像 PhoneGap 文档指定的那样,AndroidManifest.xml 的内容被删除,回到 0 KB,并且生成的 .project 文件也是空的。不仅如此,我仍然遇到同样的错误。这些在控制台...

[2013-05-21 18:27:13 - PhoneGapTest] Project has no target set. Edit the project properties to set one.
[2013-05-21 18:27:14 - PhoneGapTest] Parser exception for /PhoneGapTest/AndroidManifest.xml: Premature end of file.

..(有意义,因为 AndroidManifest 是 EMTPY),这些在错误对话框中......

Description Resource    Path    Location    Type
Archive for required library: 'E:/AndroidProjects/workspace/PhoneGapTest/libs/cordova-2.7.0.jar' in project 'PhoneGapTest' cannot be read or is not a valid ZIP file    PhoneGapTest        Build path  Build Path Problem

Parser exception for /PhoneGapTest/AndroidManifest.xml: Premature end of file.  PhoneGapTest        line 1  Android ADT Problem

The project cannot be built until build path errors are resolved    PhoneGapTest        Unknown Java Problem

Premature end of file.  AndroidManifest.xml /PhoneGapTest   line 1  Android XML Format Problem

编辑 - 好的,如果这有帮助,我创建项目的确切顺序如下......

  1. 导航到phonegap*/lib/android/bin并运行 command ./create PhoneGapTest com.gsu.PhoneGapTest PhoneGapTest。此步骤的输出如下...

    创建新的 android 项目...复制模板 jars...复制 js、jar 和 config.xml 文件...复制 cordova 命令工具...更新 AndroidManifest.xml 和 MainActivity...

  2. 使用 Android ADT 启动 Eclipse 并导航到New > Project > Android > Android Project from Existing Code

  3. 浏览到我在步骤 1 中创建 PhoneGapTest 项目的工作区,选中copy project into workspace复选框(如果我不这样做,我会看到一个消息框读取invalid project description),单击完成。

  4. 现在 PhoneGapTest 出现在项目资源管理器中,以及这些错误......

    [2013-05-22 15:36:10 - PhoneGapTest] 项目没有设置目标。编辑项目属性以设置一个。[2013-05-22 15:36:31 - PhoneGapTest] /PhoneGapTest/AndroidManifest.xml 的解析器异常:文件过早结束。

...所以我点击项目properties > Android > Project Build Target并选择Android 4.2.2(这唯一的其他选项是Google APIs

在这里,我不知道如何处理 AndroidManifest,因为它是空的。这对我来说似乎是问题的根源。当我从现有源构建 Android 项目时,AndroidManifest.xml 以某种方式变为空。

4

2 回答 2

4

好的,我知道了。我在Eclipse 工作区中使用 PhoneGapcreate实用程序创建项目。显然,当您这样做然后从现有的源 eclipse 副本和一个新的空文件创建项目时,这就是问题所在。我在我的文件系统的其他地方使用实用程序创建了项目,从 Eclipse 中的现有源创建项目并且没有选中复选框,现在一切似乎都很好,原始文件被保留了。AndroidManifest.xmlcreatecopy project into workspaceAndroidManifest.xml

于 2013-05-22T20:05:38.113 回答
0

在 Mac OS 上,您应该使用

sudo ./create ....
于 2013-06-02T09:52:29.917 回答