[英]Updating a maven library project into main project (android)
我試圖通過以下示例了解Maven Android插件: https : //github.com/jayway/maven-android-plugin-samples/archives/stable
我正在使用示例“libraryproject”,一切都運行良好,只有一件我真的無法弄清楚:如果我改變了一些東西到lib1項目(例如資源文件的內容)和complile主項目,我仍然在生成的apk文件中看到舊資源。
我試着清理,重建,沒有改變我的apk ...
對不起因為我的英語不好這個愚蠢的問題。
編輯:我只是喜歡yorkw說:
但現在我收到以下錯誤:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Library Projects Parent
[INFO] Library Projects - Library 1
[INFO] Library Projects - Library 2
[INFO] Library Projects - Main App
[INFO] Library Projects - Instrumentation Tests
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects Parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Library 1 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-lib1 ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\res, --auto-add-overlay, -A, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\assets, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Library 2 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-lib2 ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\res, --auto-add-overlay, -A, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\assets, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Main App 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-mainapp ---
[DEBUG] Expanding: C:\Users\nicola\.m2\repository\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\libraryprojects-lib1\1.0.0-SNAPSHOT\libraryprojects-lib1-1.0.0-SNAPSHOT.apklib into C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT
[DEBUG] expand complete
[DEBUG] Expanding: C:\Users\nicola\.m2\repository\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\libraryprojects-lib2\1.0.0-SNAPSHOT\libraryprojects-lib2-1.0.0-SNAPSHOT.apklib into C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT
[DEBUG] expand complete
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res, --auto-add-overlay, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO] C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res\layout\main.xml:12: error: Error: No resource found that matches the given name (at 'text' with value '@string/lib1resource').
[INFO] C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res\layout\main.xml:17: error: Error: No resource found that matches the given name (at 'text' with value '@string/lib2resource').
[ERROR] Error when generating sources.
org.apache.maven.plugin.MojoExecutionException:
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:338)
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:102)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe" package -m -J C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r -M C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res --auto-add-overlay -I "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar"", Result = 1
at com.jayway.maven.plugins.android.CommandExecutor$Factory$1.executeCommand(CommandExecutor.java:215)
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:336)
... 22 more
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Library Projects Parent ........................... SUCCESS [0.004s]
[INFO] Library Projects - Library 1 ...................... SUCCESS [1.109s]
[INFO] Library Projects - Library 2 ...................... SUCCESS [0.299s]
[INFO] Library Projects - Main App ....................... FAILURE [0.489s]
[INFO] Library Projects - Instrumentation Tests .......... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.277s
[INFO] Finished at: Wed Apr 18 02:46:34 CEST 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:generate-sources (default-generate-sources) on project libraryprojects-mainapp: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe" package -m -J C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r -M C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res --auto-add-overlay -I "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar"", Result = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :libraryprojects-mainapp
您應該在父項目文件夾(../libraryprojects)中構建項目(mvn clean install),這將構建libraryprojects-lib1項目(以便將最新的apklib安裝到您的本地maven存儲庫中)以及libraryprojects-mainapp項目。
如果在子項目文件夾(../libraryprojects/libraryprojects-mainapp)中構建項目(mvn clean install),這將只構建libraryprojects-mainapp並使用存儲在本地maven存儲庫中的現有apklib來實現項目依賴性。 換句話說,libraryprojects-lib1項目重建沒有發生,並且有助於libraryprojects-mainapp項目的構建生命周期。
請注意,如果您在Eclipse中導入整個項目並通過Eclipse清理/構建libraryprojects-mainapp,它將自動觸發依賴庫項目libraryprojects-lib1的重建過程。
更新:
我已經下載了最新的android maven插件並在我的Windows XP盒子上試一試並復制了這個問題,它實際上是一個Microsoft Fault! 如果您嘗試訪問(這是構建項目時創建的臨時文件夾Maven之一):
C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT\res
從資源管理器中,你得到:
點擊此處和此處了解更多詳情。 Windows上的最大路徑長度限制為256個字符。
解:
首先,嘗試使用短路徑,例如,可以找到以下內容:
C:\c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT\res
然后給它另一個嘗試,看看你是否可以構建它,你可能會得到另一個構建錯誤(我試過我的Windows XP框並得到此錯誤),如下所示:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.1:compile (default-compile) on project libraryprojects-mainapp: Compilation failure: Compilation failure:
[ERROR] C:\c475bf4\libraryprojects\libraryprojects-mainapp\src\main\java\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\mainapp\MainActivity.java:[16,5] annotations are not supported in -source 1.3
要解決此問題,您可以在.. \\ libraryprojects \\ pom.xml中指定更高版本的maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
最后但並非最不重要的是,請注意您需要打開模擬器才能讓測試子項目運行檢測測試,否則構建測試項目將失敗。
希望這可以幫助。
我有同樣的問題,它的解決方案是使用Eclipse Marketplace更新/安裝Maven android配置器。 (Eclipse幫助 - > Eclipse marketplace - >找到maven android配置器並安裝它)
之前我還使用Eclipse幫助更新了m2e插件 - >檢查更新
如果它沒有幫助,那么嘗試逐步搜索錯誤。 我已經描述了在這里使用android和eclipse配置maven所需的所有步驟
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.