简体   繁体   English

在运行时找不到类,但是在编译时使用命令行

[英]Class Not Found at RunTime, but there at compile time, using command line

I know my source compiles out fine in eclipse, but for the sake of easier production using the same source over and over I've opted to set up a .bat to handle most of the work for me. 我知道我的源代码可以很好地在日食中编译,但是为了方便使用同一源代码反复制作,我选择设置一个.bat来为我处理大部分工作。 Well, short and sweet, my external jars are available at compile not, however not at runTime, which I receive force closes (Android ClassNotFoundDefError). 好吧,简短而甜蜜的是,我的外部jar无法在编译时使用,但是在运行时无法使用,我收到了强制关闭(Android ClassNotFoundDefError)。 I'm sure the problem lies within how my commands are set on my .bat file, and after reading websites (I'll list a set of references I used at the end) I've came to this code.... 我确信问题出在我的.bat文件中的命令设置方式中,并且在阅读了网站之后(我将列出最后使用的一组引用),我来到了这段代码。

echo on
@REM %1 NOTUSED
@REM %2 SHORT NAME (DIR HIERARCHY POINTER)
@REM %3 SRCPATH (RECEIVES PACKAGE PATH)
@SET PREV_PATH=%CD%
@cd /d %0\..

@rmdir %2\bin /S /Q
@rmdir %2\gen /S /Q
@mkdir %2\bin || goto EXIT
@mkdir %2\gen || goto EXIT
@SET APP_NAME=%2
@SET ANDROID_REV=android-7

@SET ANDROID_AAPT_ADD="%ANDROID-SDK%\platform-tools\aapt.exe" add

@SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platform-tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar" -j ".\usrsrc\libs\MobileSDK.jar" -j ".\usrsrc\libs\MobileSDK2.jar"

@SET ANDROID_DX="%ANDROID-SDK%\platform-tools\dx.bat" --dex

@SET JAVAC="%JAVABIN%\javac.exe" -classpath ".\%2;%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar;%2\libs\MobileSDK.jar;%2\libs\MobileSDK2.jar"

@SET JAVAC_BUILD=%JAVAC% -sourcepath "%2\src;%2\gen" -d "%2\bin" -jar "%2\libs\MobileSDK.jar;%2\libs\MobileSDK2.jar"

call %ANDROID_AAPT_PACK% -M "%2\AndroidManifest.xml" -A "%2\assets" -S "%2\res" -m -J "%2\gen" -F "%2\bin\resources.ap_" -j "%2\libs\MobileSDK.jar" -j "%2\libs\MobileSDK2.jar" || goto EXIT

call %JAVAC_BUILD% %2%3*.java || goto EXIT

call %ANDROID_DX% --output="%CD%\%2\bin\classes.dex" %CD%\%2\bin || goto EXIT

copy "%CD%\%2\bin\resources.ap_" "%CD%\%2\bin\%APP_NAME%.ap_" || goto EXIT

call %ANDROID_AAPT_ADD% "%CD%\%2\bin\%APP_NAME%.ap_" "%CD%\%2\bin\classes.dex" || goto EXIT

call "%JAVABIN%\jarsigner" -keystore "%CD%\keystore.keystore" -storepass "XXXXXXXXXX" - keypass "XXXXXXXX" -signedjar "%CD%\%2\%APP_NAME%.apk" "%CD%\%2\bin\%APP_NAME%.ap_" "XXXXXXXXX" || goto EXIT
del "%2\bin\%APP_NAME%.ap_"
:EXIT
cd "%PREV_PATH%"
ENDLOCAL
pause
exit /b %ERRORLEVEL%

Now I know I'm prolly gonna feel really really stupid whenever someone shows me how painfully obvious the answer is. 现在我知道,只要有人向我展示答案的明显程度,我就会感到非常愚蠢。 But I've been on this one thing for about 24 hours now, and I just can't stand it any longer. 但是我已经在这件事上待了大约24个小时,而我忍受不了了。 I would greatly appreciate any help. 我将不胜感激任何帮助。

FYI: Most of the variables fed into this bat are fed from another program that sets up the file hierarchy and everything else before we even go to the .bat. 仅供参考:送入此bat的大多数变量是从另一个程序建立的,该程序设置了文件层次结构以及其他所有内容,甚至在我们转到.bat之前。 That's all I can really describe about this issue. 这就是我真正能描述的所有内容。

Reference: 参考:
http://www.herongyang.com/Android/Project-aapt-Android-Asset-Packaging-Tool.html http://www.herongyang.com/Android/Project-aapt-Android-Asset-Packaging-Tool.html
http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line
and all the questions about external jar's on stack overflow; 有关外部jar的所有问题都在堆栈上溢出; There are a few more; 还有更多; I fail to find at the moment will update as I do. 我现在无法找到将更新的内容。

Because unlike some people; 因为与某些人不同; I did want to help, and have received answers lurking stack overflow before in the past, I came back after I researched the answer because I have seen this question a number of times across stack overflow with no one giving out a correct answer to this: 我确实想提供帮助,并且在过去曾经收到过有关堆栈溢出的答案,在研究了答案之后我又回来了,因为我在堆栈溢出中多次看到此问题,而没有人给出正确的答案:

"You have to explicitly call for your external jars inside of dx.bat" “您必须在dx.bat内显式调用您的外部jar”

call %ANDROID_DX% --output="%CD%\%2\bin\classes.dex" "%CD%\%2\bin" "C:\<dir>\mobileSDK.jar" "C:\<dir>\MobileSDK2.jar" || goto EXIT

You have to give a static address WITHOUT SPACES IN IT in order to comply with "java standards" (see my references above in the question). 为了符合“ java标准”,您必须提供一个静态地址,且没有空格,以确保其符合Java标准(请参阅我上面提到的问题)。 This tells the Android building stuff to include those two jars as compiled code. 这告诉Android建筑物将这两个jar作为编译代码包括在内。


The first call for them 他们的第一个电话

@SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platform-tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar" -j ".\usrsrc\libs\MobileSDK.jar" -j ".\usrsrc\libs\MobileSDK2.jar"

Is soley for them to be apparant during compileTime and have the classes available for the compiler to avoid throwing errors for lack of a better term. 希望他们在compileTime期间表现出色,并为编译器提供可用的类,以避免由于缺少更好的术语而引发错误。
Including them in dx.bat as well tells it to include those .jars along with all the .class files when compacting it into an APK. 将它们包含在dx.bat中还告诉它在将其压缩为APK时,将那些.jar和所有.class文件包括在内。 But I hope this helps someone in the future. 但我希望这对将来的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 除了使用 Scanner 类和命令行之外,还有其他更短的方法可以在编译时在 Java 中传递值吗? - Is there any other shorter method to to pass values at compile time in java other then using Scanner class and Command line? 类加载:编译时或运行时 - Class Loading: Compile time or Runtime jar中的类在运行时未找到,但用于编译 - Class in jar not found at runtime, but was used to compile 如何在一个类中使用Javac为命令行自动编译? - How to Auto Compile For the Command Line Using Javac From Within a Class? 如何使用命令行编译和运行多个 class 的 java 项目? - How compile and run java project with multiple class using command line? 从命令行(不使用lein)将clojure源编译为类(AOT) - Compile clojure source into class (AOT) from command line (not using lein) 尝试通过命令行使用javac编译类文件将返回“找不到文件” - Attempting to compile class file through command line with javac returns “File not found” Java运行时保留批注-在编译时需要批注类,但在运行时不需要吗? - Java runtime retention annotations - annotation class required at compile time but not at runtime? 如何使用命令行编译java文件? - How to compile a java file using the command line? 在编译时或运行时编程 - Programming at compile time or at runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM