使用Eclipse从命令行构建Android项目

时间:2011-12-09 10:52:45

标签: android eclipse command-line build

我在Windows 7 64位上在Eclipse(Indigo)中创建了一个“Hello World”Android项目。它使用的是Android SDK 1.6。

它从IDE构建而没有任何问题。

现在我想从命令行构建它。 我发现了这个问题:Opening an eclipse project through command prompt or batch fileHeadless Building with APT in Eclipse,所以我跑了这个:

C:\inst\Android\eclipse>eclipsec.exe -data "C:\eclipsewsTest1" -application org.
eclipse.jdt.apt.core.aptBuild

我得到的是以下内容:

Building workspace
Building '/And1'
Invoking builder on '/And1'.
Invoking builder on '/And1'.
Invoking 'Java Builder' on '/And1'.
Cleaning output folder for And1
Build done
Invoking builder on '/And1'.

然后会出现一个对话框,显示以下消息:

An error has occurred. See the log file C:\eclipsewsTest1\.metadata\.log

此日志文件包含以下内容:

eclipse.buildId=M20110909-1335
java.version=1.7.0_01
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.java.product -application org.eclipse.jdt.apt.core.aptBuild
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product -data C:\eclipsewsTest1 -application org.eclipse.jdt.apt.core.aptBuild

!ENTRY org.eclipse.core.resources 2 10035 2011-12-09 10:50:35.233
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.

!ENTRY org.eclipse.osgi 4 0 2011-12-09 10:50:35.553
!MESSAGE An error occurred while automatically activating bundle com.android.ide.eclipse.ddms (351).
!STACK 0
org.osgi.framework.BundleException: Exception in com.android.ide.eclipse.ddms.DdmsPlugin.start() of bundle com.android.ide.eclipse.ddms.

有人知道问题是什么吗?

2 个答案:

答案 0 :(得分:15)

# 1. go into you Eclipse project
cd "C:\Users\username\workspace\app"

# 2. create build files (only first time)
"C:\Program Files\Android\android-sdk\tools\android.bat" update project --path .

# 3. Set Java JDK Path
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_25

# 4. Build with "ant debug"
"C:\Program Files\eclipse\plugins\org.apache.ant_1.8.3.v20120321-1730\bin\ant" debug

# 5. Deploy (and replace existing with -r)
"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" 
   install -r "C:\Users\username\workspace\app\bin\appActivity-debug.apk"

# 6. Run it. Look up package and activity name in `AndroidManifest.xml`
"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" 
   shell am start -n <your_package>/<activity_android:name>

# 7. View log.
"C:\Program Files\Android\android-sdk\platform-tools\adb.exe" logcat

另见this blogAndroid help

答案 1 :(得分:0)

我强烈建议使用标准的正确方法来构建使用像ant这样的构建工具。 ADT为ant提供了很好的支持,并使用你的eclipse项目为你生成构建脚本。因此整体工作量非常小而且速度很快。你可以在这里找到如何做到这一点:

http://pissedoff-techie.blogspot.in/2014/07/how-to-build-android-project-in-eclipse.html