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.
Related
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.
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 want to use dx tool. So I use the following command in terminal
dx --dex --output=classes.dex sample.jar
and I got this error
No such file or directory
I know i should set environment variable "path" and add /build-tools/x.y.z/dx to it. But even set the path doesn't resolve the error. I should mention that I can run it from /build-tools/x.y.z/ by running the command
./dx
but i need to access dx from any directory, for my project purpose. I use ubuntu 14.04 64 bit. How can I fix it?
I'm compiling my (fairly simple, just 5 files with few hundred LOC) app from command line on OSX using:
ant debug
It works. But it works slowly:
BUILD SUCCESSFUL
Total time:
26 seconds
Why is that? It takes this much time even if I change only one line in one java file. Most of this time is spent in dex stage (about 20 seconds), which is AFAIK creating Dalvik bytecode. But my friend that also works on the same project on Windows using Eclipse says that compiling takes only a second or two on his machine. Is there anything I can do to speed up this proccess?
I finally found a solution for this! It's a bit of a hack, but it works.
First, go to your ANDROID-SDK/platform-tools directory, then rename dx app to something else, like dextool, and finally create new dx file with contents:
#!/bin/sh
shift
dextool --dex --incremental --no-optimize $#
Replace "dextool" with the name you chose before. This will prepend (undocumented) --incremental attribute to every dex invocation, which will massively decrease build times by dexing only classes that have changed between builds. Now it looks like this:
[dx] Merged dex A (1 defs/11,3KiB) with dex B (359 defs/1253,2KiB). Result is 359 defs/1519,3KiB. Took 0,5s
0.5s instead of 20s is a huge difference!
Edit - few remarks:
you have to compile your project at least once before using this, because it uses previous classes.dex file
you can run into problems when using other Android toolchains than ant
UPDATE:
Google released SDK Tools 21.0, which renders above tweak absolete, because it does supports pre-dexing. Finally!
Even in 21.1.1 with the --incremental --no-optimize added in the original dex.bat it is slow, so I went on to figure something out, the result is: if you order the .jar files passed to dex by size you get better performance.
Watch https://code.google.com/p/android/issues/detail?id=79166 for updates, I hope they agree and this goes into vNext.
#!/usr/bin/perl
use strict;
use warnings;
#use Data::Dump qw(dump);
use List::Util qw(first), qw(sum);
# size of the argument, -s for files, -s on **/*.class for folders
sub size {
if (-d $_) {
# directory size is sum of all class files in the dir recursively
# account for pre-dexing and compression with a 25% decrease
return sum(map { size($_) * 0.25 } <$_/*.class>) || 0;
}
return -s $_; # use built-in size operator
}
my $dx_args_with_args =
qr/^--(output|positions|(no-)?optimize-list|dump-(to|width|method)|num-threads|main-dex-list|input-list)$/;
my $nArgs = $#ARGV;
# last argument like --blah, those are for dx
my $lastArg = $nArgs - first { $ARGV[$nArgs - $_] =~ /^--/ } 0..$nArgs;
if ($lastArg != -1 && $ARGV[$lastArg] =~ /$dx_args_with_args/) {
$lastArg += 1;
}
my #inputs = map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [size(), $_] }
#ARGV[$lastArg + 1 .. $nArgs];
print join(" ", #ARGV[0..$lastArg], #inputs);
exit 0;
Usage
have Perl on your path
copy the above perl script to ANDROID-SDK/build-tools/v.v.v/dx.pl
rename dx in ANDROID-SDK/build-tools/v.v.v/
Unix: rename dx to dx-orig
Windows: rename dx.bat to dx-orig.bat
add a new replacement dx which calls through:
Windows: dx.bat
#echo off
setlocal
set args=%*
for /f "delims=" %%i in ('perl "%~dp0dx.pl" %args%') do set args=%%i
call "%~dp0dx-orig.bat" %args%
endlocal
Unix: dx
#!/bin/sh
dx-orig `perl dx.pl $#`
I have a kind of strange issue. In my bash script or Makefile, using aapt with absolute path does not work but if I am in the local directory it does.
If I do the following, it does not work:
aapt add $OUT/device.jar $OUT/classes.dex
The command does run and print this output:
'/homes/rsevile/CS307/bin/Device/classes.dex'...
But when trying to load the jar, the class that I am trying to load end up being not found.
The following does work though:
cd $OUT
aapt add device.jar classes.dex
Printing:
'classes.dex'...
This is the whole code being executed in the script (which works):
javac -d $(OUT)/classes -classpath ./layoutlib.jar src/com/device/client/*.java
jar cf $(OUT)/device.jar $(OUT)/classes $(OUT)/layoutlib
dx --dex --no-strict --output=$OUT/classes.dex $OUT/device.jar
cd $OUT
aapt add device.jar classes.dex
cd $ROOT
adb push $OUT/device.jar $ANDROID_OUT_DIR
I am confused why my class ends up being not found when using an absolute path with aapt.
Could anyone please explain to me why it is not working and how I could fix it to use a proper absolute path please?
Thank you.
I realized that aapt actually keeps the absolute path, there is no way around it.
I fixed the problem by reusing jar and using the -C option that lets me specify a directory.