There is a jar
named 353.jar
in a directory. I new a java class and import a class that is in 353.jar
.
import com.coxier.test.DrawaerLayout;
class Test {
public static void main(String[] args) {
DrawaerLayout d = new DrawaerLayout();
}
}
I compile Test.java
with below command:
javac -verbose -classpath /Users/coxier/test/app/build/intermediates/transforms/dexBuilder/debug/353.jar:. TestA.java
But here is a error:
error: package com.coxier.test does not exist
Thanks @Marquis. I know this jar is a dex format file.
jar tvf 351.jar
The output is:
1080024 Thu Jul 02 17:52:10 CST 2020 classes.dex
javac has nothing to do with android.
Android development can be done using a language that is extremely java like but not quite java. In particular, all the infrastructure around it, such as what the compiled code looks like, is entirely non-java (as in, the tooling that ships with not-android-targeted java, such as your OpenJDK installation, doesn't know about it and can't read any of it).
That jar file contains, as far as java itself is concerned (and javac is just java, not android), absolutely nothing: It has no idea what a dex file is, so that is just ignored.
This code would work if the jar file contained the entry:
/com/coxier/test/DrawaerLayout/Test.class
then, javac -cp thatJar.jar TestA.java
would work, assuming TestA.java
is in the current working directory and contains:
import com.coxier.test.DrawaerLayout.Test;
public class TestA {
Test test;
}
If you have the source of that Test.dex
file, you could make a class file instead, but it sounds like what you need is for TestA.java
to also be compiled with the android toolkit, which presumably does know what dex files are, and may even accept them in jars (though I recall that jars aren't a thing android does either, just like it doesn't 'do' class files).