I used to create dex file with dx.bat like this :
"c:\SDKs\android\build-tools\32.0.0\dx.bat" --dex
--output=C:\Dev\MagicFoundation\Alcinoe\Tools\AddRJavaToClassesDex\tmp\classes.dex
C:\Dev\MagicFoundation\Alcinoe\Tools\AddRJavaToClassesDex\tmp\obj.zip
How to do the same with d8.bat?
Creating DEX file using d8 can be achieved using:
d8 --output <output-folder> <input-files>
In your case, the following is an equivalent:
c:\SDKs\android\build-tools\32.0.0\d8.bat --output C:\Dev\MagicFoundation\Alcinoe\Tools\AddRJavaToClassesDex\tmp C:\Dev\MagicFoundation\Alcinoe\Tools\AddRJavaToClassesDex\tmp\obj.zip
To anyone who is using d8.bat with OpenJDK-11, if you encounter the error when running d8.bat:
-Djava.ext.dirs=${PathToAndroidSDK}\build-tools${BuildToolVersion}\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
You can edit d8.bat with a text editor, replacing the code -Djava.ext.dirs="%frameworkdir%" in last line to -classpath "%frameworkdir%" to fix the error.
Related
I am trying to build Android apps manually from the command line.
But, whenever I am running dx.bat command which is located inside the Android SDK build-tools directory, I am always getting an error. Whichever option I give, I always get the same error. While running dx --help, I got this error :
-Djava.ext.dirs=E:\.android\SDK\build-tools\29.0.2\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
When I had Android Studio, I didn't get any such problems. What mistake am I doing and how to get the dx.bat file to work right?
I had solved this issue by editing the dx.bat file.
As mentioned in the error
-Djava.ext.dirs=E:\.android\SDK\build-tools\29.0.2\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
I had just changed this line of the dx.bat file (last line) :
call "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params%
to this :
call "%java_exe%" %javaOpts% -classpath "%frameworkdir%" -jar "%jarpath%" %params%
I get the following error, but when I increase the Max Heap Size, it doesn't have any effect. I have gone up to 8G with no change. Is there something else going on?
Suppression State
Error java.lang.OutOfMemoryError. Consider increasing the value of $(JavaMaximumHeapSize). Java ran out of memory while executing 'java.exe -Xmx1G -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\lib\dx.jar" --dex --no-strict --output obj\Debug\android\bin "C:\code\Droid\obj\Debug\android\bin\classes.zip" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v8.0\mono.android.jar" obj\Debug\lp\10\jl\bin\classes.jar obj\Debug\lp\11\jl\bin\classes.jar obj\Debug\lp\12\jl\bin\classes.jar obj\Debug\lp\13\jl\bin\classes.jar obj\Debug\lp\14\jl\bin\classes.jar obj\Debug\lp\15\jl\bin\classes.jar obj\Debug\lp\16\jl\bin\classes.jar obj\Debug\lp\17\jl\bin\classes.jar obj\Debug\lp\18\jl\bin\classes.jar obj\Debug\lp\19\jl\classes.jar obj\Debug\lp\20\jl\classes.jar obj\Debug\lp\21\jl\classes.jar obj\Debug\lp\22\jl\classes.jar obj\Debug\lp\3\jl\arch-core-common.jar obj\Debug\lp\4\jl\arch-lifecycle-common.jar obj\Debug\lp\5\jl\bin\classes.jar obj\Debug\lp\6\jl\bin\classes.jar obj\Debug\lp\8\jl\bin\classes.jar obj\Debug\lp\9\jl\bin\classes.jar'
Delete bin and object files. If you are using Mac i would recommend adding nice plugin:
enter link description here
I am using Ubuntu14.04, Eclipse Luna.
I am referring Hello World Example given link
http://www.ntu.edu.sg/home/ehchua/programming/android/Android_NDK.html
My project name is HelloNDK.
My project path is /home/androiddev/workspace_luna/HelloNDK
In AndroidManifest.xml
I can see package which I use is named as: com.delta.hellondk
Android.jar which automatically added in project which is under Android 5.0.1 & its location shown as
/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar
When I use javah command, I got error.
I use following line in terminal.
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
&
javah -jni -classpath /home/androiddev/workspace_luna/HelloNDK/bin/classes/JNIActivity.class;/home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar -o HelloJNI.h com.delta.hellondk
when I use following command, I got error as follows:
Error: No classes were specified on the command line. Try -help.
bash: /home/androiddev/Applications/Android_sdk/sdk/platforms/android-21/android.jar: cannot execute binary file: Exec format error
Now I search lots of keywords in google, stackoverflow regarding how to generate HelloJNI.h automatically.
But i failed.
Please guide me!
I know its repeate question should be get negative vote, should be 'On Hold'. But then also i doesn’t get any clue so i asked without hesitate.
I'm trying to including the NewRelic library into my project, but I get this error when I build it
Error:Execution failed for task ':v1:preDexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Program Files\Android\android-studio\sdk\build-tools\19.1.0\dx.bat --dex --output
C:\Documents and Settings\t.hart\My Documents\Android\MoneyTracker\v1\build\pre-dexed\debug\android-agent-3.378.0-27125f93a249f513379e837d75ebec255f6dcaa4.jar
C:\Documents and Settings\t.hart\.gradle\caches\modules-2\files-2.1\com.newrelic.agent.android\android-agent\3.378.0\1ebf0e20081a7f1b9a5c31bfc4e7dba776e0c171\android-agent-3.378.0.jar
Error Code:
1
Output:
Error opening zip file or JAR manifest missing : C:\Documents
To include the library you need to add 3 lines to your build.gradle files,
//This to the buildscript dependancies
classpath 'com.newrelic.agent.android:agent-gradle-plugin:3.378.0'
//This line (in the example it's under the android line
apply plugin: 'newrelic'
//And this to dependancies
compile 'com.newrelic.agent.android:android-agent:3.378.0'
After some trial and error it seems it's the last line (the compile one) that's causing the error to be thrown. Is this because of the spaces in C:/Documents And Settings?
I'm also using these librarys, and they all downloaded to the build/pre-dexed/debug folder fine with no issues.
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.android.support:gridlayout-v7:19.1.0'
compile 'com.android.support:support-v4:19.1.0'
EDIT: Updated error message
Error:Execution failed for task ':v1:preDexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Program Files\Android\android-studio\sdk\build-tools\19.1.0\dx.bat --dex --output
C:\MoneyTracker\v1\build\pre-dexed\debug\support-v4-19.1.0-cd41ef807caadb29c9df0131dee869d3723185ad.jar
C:\Program Files\Android\android-studio\sdk\extras\android\m2repository\com\android\support\support-v4\19.1.0\support-v4-19.1.0.jar
Error Code:
1
Output:
Error opening zip file or JAR manifest missing : C:\Documents
Now that's a strange error...
It effectively has to do with spaces in your folders names, the error message tells you gradle can't find a zip or jar manifest in C:\Documents, which is obviously not the folder your newrelic library is in. Try moving your project in a directory which name doesn't have space. Make it a habit, some tools really don't like spaces in filenames (especially unix rooted one).
You can set the GRADLE_USER_HOME environment variable, gradle.user.home system property, or --gradle-user-home command line parameter to directory which name doesn't have space.
(via How to change Gradle download location)
I am trying to create a simple JAR file like here and execute it in the shell. i am stuck on this line
dx --dex --output=foo.jar Foo.class
when i execute this line in CMD . I am always getting an error like this
trouble processing:
class name (com/delvix2/Foo) does not match path (C:/somepathhere/classes/com/delvix2/Foo.class)
...while parsing C:/somepathhere/classes/com/delvix2/Foo.class
...while processing C:/somepathhere/classes/com/delvix2/Foo.class
1 warning
no classfiles specified
How can I fix this issue?
This works for me.
dx --dex --output="full path to dex file\file.dex" "c:\.....path to folder which contains the class file only"
First path : full path to dex file including the name of the dex file you want
Second path : Path to a folder which contains "ONLY" your .class file.
(Just give the path up to the folder, don't give the class file name)
It looks like dx expects that the relative path of the class that you give it will match it's package. Try this instead:
cd c:/somepathhere/classes
dx --dex --output=foo.jar com/delvix2/Foo.class
Use the --no-strict option:
dx --dex --no-strict --output=foo.jar Foo.class
It must be in your case
dx --dex --output=C:\classes.dex C:\temp\Foo.jar
and then you must use
aapt add C:\temp\Foo.jar C:\classes.dex
I hope it will be work
I tried all this, and did not work. There's something that worked for me, and it was to put your classes in \sdk-path\platforms-tools\. For example,
C:\sdk-path\platforms-tools\dx --dex --output=class.dex com\mypack\app\myclass.class
And myclass.class lives in,
C:\sdk-path\platforms-tools\com\mypack\app\myclass.class
This is crappy, but the only thing that worked.