Can't reference classes from Java Project. ADT 17 Preview 4.

506 views
Skip to first unread message

alex2k8

unread,
Mar 9, 2012, 6:43:32 AM3/9/12
to adt-dev
ProjA - Java Project

public class A {
public void m1() {}
}

ProjB - Android Project

Properties > Java Build Path > ProjA


And from ProjB I am calling the class A:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new A().m1();
}

But I get such error:

03-09 15:34:27.790: E/dalvikvm(7802): Could not find class
'com.test.A', referenced from method com.test.MainActivity.onCreate
03-09 15:34:27.790: W/dalvikvm(7802): VFY: unable to resolve new-
instance 5 (Lcom/test/A;) in Lcom/test/MainActivity;
03-09 15:34:27.790: D/dalvikvm(7802): VFY: replacing opcode 0x22 at
0x0008
03-09 15:34:27.790: D/dalvikvm(7802): DexOpt: unable to opt direct
call 0x0004 at 0x0a in Lcom/test/MainActivity;.onCreate
03-09 15:34:27.820: D/AndroidRuntime(7802): Shutting down VM
03-09 15:34:27.820: W/dalvikvm(7802): threadid=1: thread exiting with
uncaught exception (group=0x40a3b1f8)
03-09 15:34:27.820: E/AndroidRuntime(7802): FATAL EXCEPTION: main
03-09 15:34:27.820: E/AndroidRuntime(7802):
java.lang.NoClassDefFoundError: com.test.A
03-09 15:34:27.820: E/AndroidRuntime(7802): at
com.test.MainActivity.onCreate(MainActivity.java:13)
...

How to fix this issue?
Message has been deleted

Andrei Bulanau

unread,
Mar 9, 2012, 11:05:18 AM3/9/12
to adt...@googlegroups.com
I have a similar error. I rolled back to preview 3.

Xavier Ducrohet

unread,
Mar 9, 2012, 1:42:02 PM3/9/12
to adt...@googlegroups.com
well that's just weird. I have a test project that does just that and it works.
Can you enable verbose output in the prefs under Android > Build to see what is passed to dx?

Your project A is a Java-only project, right? If it has the Android Nature it won't get included (by design).
--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

John M

unread,
Mar 22, 2012, 4:04:28 AM3/22/12
to adt...@googlegroups.com
So you guys were made aware of this issue before the general release and didn't fix it.  Thanks.

Ricardo Gladwell

unread,
Mar 22, 2012, 11:08:33 AM3/22/12
to adt...@googlegroups.com
It looks as though this might well be the case. This may have broken m2e ADT support for the m2e-android project:

http://rgladwell.github.com/m2e-android/

--
Ricardo Gladwell <ricardo....@gmail.com>
Web: http://gladwell.me/ - Twitter: @rgladwell
GTalk: ricardo....@gmail.com

Xavier Ducrohet

unread,
Mar 23, 2012, 2:47:21 PM3/23/12
to adt...@googlegroups.com
The particular problem in the original email is unreproducible by us, and we never got any answers to our questions.

If you can't make it work, please let me know what your project set up looks like (after reading all of http://tools.android.com/recent/dealingwithdependenciesinandroidprojects to make sure you made required changes), and we'll try to figure out what's going on.

Xavier Ducrohet

unread,
Mar 23, 2012, 2:50:37 PM3/23/12
to adt...@googlegroups.com
This is unrelated to the original post.

The maven support in Eclipse may be broken. I'll admit we don't actually test it. I don't neven know who works on it and if they are on this list (unlike straight Maven support where I know Manfred reads this list).

For r18, we're working towards moving back to working directly in the open. We'll try to notify this list of all build system changes going in so that every one can follow and adapt 3rd party build system to stay compatible. Hopefully the Maven/EClipse integration folks can read this list and keep up.

Xavier Ducrohet

unread,
Mar 23, 2012, 2:52:57 PM3/23/12
to adt...@googlegroups.com
Well this is interesting. I'm catching up on unread email in this list, and I just read in another thread that you are working on the Maven/Eclipse integration!
I'll keep that in mind. Let me know if there's anything I can do to help fix the maven issue.

Ricardo Gladwell

unread,
Mar 24, 2012, 2:20:43 PM3/24/12
to adt...@googlegroups.com
Hi Xavier

I've only just discovered this mailing list myself so I'll try and stay tuned, although I don't find mailing lists are the best way to keep up-to-date. I think people tend to dip in and out of them.

I'm currently in the process of working on a fix for Maven/Eclipse/ADT integration (or as we call it, m2e-android).

In future, I'm planning set-up a continuous integration build that runs out test suite against the latest beta of the ADT. If you guys ever decide to publish a p2 repository for ADT, that would help me out in this endeavour :)

Regards...

-- Ricardo Gladwell

Ievgenii Nazaruk

unread,
Mar 24, 2012, 8:03:12 PM3/24/12
to adt-dev
I am also seeing this issue and I have repro steps for this.

Let's assume I have two eclipse projects:
* jar
* app (references jar)

If I directly include "jar" project as reference under "Java Build
Path"->Project. Eclipse compiles the code correctly (i.e. I can use
classes from "jar" projects). Though dexer simply ignores .class files
generated by "jar" project and never includes them in final .dex file.
Also under "Android Dependencies" there is only "annotations.jar" (no
mentions of "jar" project).

This "app" project compiles but crashes at runtime due to missing
classes from "jar" .

You can find example of this configuration here:
https://github.com/inazaruk/examples/tree/master/JarDependency/case1

*********************

Now about second case which makes these things work. If we introduce
another project called "lib" :

* jar
* lib (references jar)
* app (referneces lib)

Where "lib" is Android Library. Now you need to go to "lib" project
and add "jar" project at "Java Build Path" -> Project tab and export
it on "Order and Export" tab.
After this is done, go to "app" project and add "lib" as Andorid
Library through "Android" menu in Project properties.

This will result in working application. The interesting part: if you
now go to "lib" project and check "Android Dependencies" you won't see
"jar" there. But if you go to "app" project and look under "Android
Dependencies" you'll see both "lib" and "jar" dependencies there.

You can see an example of this configuration here:
https://github.com/inazaruk/examples/tree/master/JarDependency/case2

**************

The conclusion: direct dependency on java project (which I'm calling
"jar" here) isn't working; but transitive dependency through another
android library works just fine.


On Mar 23, 8:47 pm, Xavier Ducrohet <x...@android.com> wrote:
> The particular problem in the original email is unreproducible by us, and
> we never got any answers to our questions.
>
> If you can't make it work, please let me know what your project set up
> looks like (after reading all ofhttp://tools.android.com/recent/dealingwithdependenciesinandroidprojectsto
> make sure you made required changes), and we'll try to figure out what's
> going on.
>
>
>
>
>
>
>
>
>
> On Thu, Mar 22, 2012 at 1:04 AM, John M <john.mickelo...@gmail.com> wrote:
> > So you guys were made aware of this issue before the general release and
> > didn't fix it.  Thanks.
>
> > On Friday, March 9, 2012 6:43:32 AM UTC-5, alex2k8 wrote:
>
> >> ProjA - Java Project
>
> >>     public class A {
> >>         public void m1() {}
> >>     }
>
> >> ProjB - Android Project
>
> >>   Properties > Java Build Path > ProjA
>
> >> And from ProjB I am calling the class A:
>
> >>     public void onCreate(Bundle savedInstanceState) {
> >>         super.onCreate(**savedInstanceState);
> >>         setContentView(R.layout.main);
> >>         new A().m1();
> >>     }
>
> >> But I get such error:
>
> >> 03-09 15:34:27.790: E/dalvikvm(7802): Could not find class
> >> 'com.test.A', referenced from method com.test.MainActivity.onCreate
> >> 03-09 15:34:27.790: W/dalvikvm(7802): VFY: unable to resolve new-
> >> instance 5 (Lcom/test/A;) in Lcom/test/MainActivity;
> >> 03-09 15:34:27.790: D/dalvikvm(7802): VFY: replacing opcode 0x22 at
> >> 0x0008
> >> 03-09 15:34:27.790: D/dalvikvm(7802): DexOpt: unable to opt direct
> >> call 0x0004 at 0x0a in Lcom/test/MainActivity;.**onCreate
> >> 03-09 15:34:27.820: D/AndroidRuntime(7802): Shutting down VM
> >> 03-09 15:34:27.820: W/dalvikvm(7802): threadid=1: thread exiting with
> >> uncaught exception (group=0x40a3b1f8)
> >> 03-09 15:34:27.820: E/AndroidRuntime(7802): FATAL EXCEPTION: main
> >> 03-09 15:34:27.820: E/AndroidRuntime(7802):
> >> java.lang.**NoClassDefFoundError: com.test.A
> >> 03-09 15:34:27.820: E/AndroidRuntime(7802):         at
> >> com.test.MainActivity.**onCreate(MainActivity.java:13)
> >> ...
>
> >> How to fix this issue?
>
> --
> Xavier Ducrohet
> Android SDK Tech Lead
> Google Inc.http://developer.android.com|http://tools.android.com

Ricardo Gladwell

unread,
Mar 25, 2012, 10:28:48 AM3/25/12
to adt...@googlegroups.com
Hi Everyone

I've just fixed the ADT 17 m2e-android bug:

https://github.com/rgladwell/m2e-android/commit/7fee3364c21f8f87020851925dd797119ccaf9f7

You can test this fix before release by using the snapshot/master update site:

http://rgladwell.github.com/m2e-android/updates/master/

Please let me know of any problems/feedback here:

https://github.com/rgladwell/m2e-android/issues/72

Regards...

-- Ricardo Gladwell

Xavier Ducrohet

unread,
Mar 26, 2012, 6:43:00 PM3/26/12
to adt...@googlegroups.com
On Sat, Mar 24, 2012 at 5:03 PM, Ievgenii Nazaruk
<ievgenii...@gmail.com> wrote:
>
> I am also seeing this issue and I have repro steps for this.
>
> Let's assume I have two eclipse projects:
>  * jar
>  * app (references jar)
>
> If I directly include "jar" project as reference under "Java Build
> Path"->Project. Eclipse compiles the code correctly (i.e. I can use
> classes from "jar" projects). Though dexer simply ignores .class files
> generated by "jar" project and never includes them in final .dex file.
> Also under "Android Dependencies" there is only "annotations.jar" (no
> mentions of "jar" project).
>
> This "app" project compiles but crashes at runtime due to missing
> classes from "jar" .

Did you mark the project as exported?


> You can find example of this configuration here:
> https://github.com/inazaruk/examples/tree/master/JarDependency/case1
>
> *********************
>
> Now about second case which makes these things work. If we introduce
> another project called "lib" :
>
> * jar
> * lib (references jar)
> * app (referneces lib)
>
> Where "lib" is Android Library. Now you need to go to "lib" project
> and add "jar" project at "Java Build Path" -> Project tab and export
> it on "Order and Export" tab.
> After this is done, go to "app" project and add "lib" as Andorid
> Library through "Android" menu in Project properties.
>
> This will result in working application. The interesting part: if you
> now go to "lib" project and check "Android Dependencies" you won't see
> "jar" there. But if you go to "app" project and look under "Android
> Dependencies" you'll see both "lib" and "jar" dependencies there.

This is normal.

Android Dependencies is really for stuff that's added automatically for you.
In lib, you have added jar manually so it doesn't show up there.
In app, both lib and jar were added automatically for you based on the
lib reference in project.properties so they show up.

Ievgenii Nazaruk

unread,
Mar 26, 2012, 6:58:27 PM3/26/12
to adt...@googlegroups.com
> Did you mark the project as exported?

I might be missing something here, but as far as I understand you only can export _referenced_ libraries and _referenced_ projects. The classes from project itself is always exported (you can't unexport it). So to answer your question: yes, the "jar" project exports its classes; and this doesn't help.

Note that "jar" project doesn't use any external jars.
Reply all
Reply to author
Forward
0 new messages