j2objc NoSuchMethodError

223 views
Skip to first unread message

confile

unread,
Mar 31, 2015, 3:24:07 PM3/31/15
to j2objc-...@googlegroups.com
I tried to use Dagger2 with J2Objc. As it was proposed I use javac to test if everything compiles. Here is what I did: 

javac -d build/classes -sourcepath src/main/java:build/source/apt src/main/java/com/example/Tester.java src/main/java/com/example/TesterImpl.java src/main/java/com/example/SomeClassB.java -classpath lib/javax.inject-1.jar:lib/dagger-compiler-2.0-20150318.194524-17-jar-with-dependencies.jar

This work fine then I switched to j2objc:

j2objc --no-package-directories -use-arc -d build/classes -sourcepath src/main/java:build/source/apt src/main/java/com/example/Tester.java src/main/java/com/example/TesterImpl.java src/main/java/com/example/SomeClassB.java -classpath lib/javax.inject-1.jar:lib/dagger-compiler-2.0-20150318.194524-17-jar-with-dependencies.jar

And I got the following errors: 


1. ERROR in /Users/mg/Documents/Grails/GGTS3.6.2/TestJ2Objc/src/main/java/com/example/Starter.java (at line 0)

package com.example;

^

Internal compiler error: java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap; at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:225)

----------

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap;

at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:225)

at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)

at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)

at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)

at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:820)

at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:434)

at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4099)

at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1689)

at com.google.devtools.j2objc.TranslationProcessor.processAnnotations(TranslationProcessor.java:175)

at com.google.devtools.j2objc.TranslationProcessor.processFiles(TranslationProcessor.java:118)

at com.google.devtools.j2objc.J2ObjC.main(J2ObjC.java:197)


 -----


Here is my ApplicationModule.java: 

package com.example;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

@Module
public class ApplicationModule {

@Provides
@Singleton
Tester provideTester() {
return new TesterImpl();
}

}


and here is my ApplicationComponent.java:

package com.example;

import javax.inject.Singleton;

import dagger.Component;


@Component(modules = {ApplicationModule.class})
@Singleton
public interface ApplicationComponent {

Tester getTester();
}

Tom Ball

unread,
Mar 31, 2015, 4:03:42 PM3/31/15
to j2objc-...@googlegroups.com
The dagger-compiler-2.0-20150318.194524-17-jar-with-dependencies.jar must include a newer version of Guava. Try putting j2objc's guava-jdk5.jar at the start of the classpath.

--
You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to j2objc-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

confile

unread,
Mar 31, 2015, 6:31:01 PM3/31/15
to j2objc-...@googlegroups.com
Okay I see what you mean. I took guava-jdk5-16.0.jar and  guava-16.0.jar.

Here is my new command: 

j2objc --no-package-directories -use-arc -d build/classes -sourcepath src/main/java src/main/java/com/example/Tester.java src/main/java/com/example/TesterImpl.java src/main/java/com/example/SomeClassB.java src/main/java/com/example/ApplicationModule.java src/main/java/com/example/ApplicationComponent.java src/main/java/com/example/Starter.java -classpath lib/guava-jdk5-16.0.jar:lib/guava-16.0.jar:lib/javax.inject-1.jar:lib/dagger-compiler-2.0-20150318.194524-17-jar-with-dependencies.jar

But still I get the errors: 


1. ERROR in /Users/mg/Documents/Grails/GGTS3.6.2/TestJ2Objc/src/main/java/com/example/Starter.java (at line 0)

package com.example;

^

Internal compiler error: java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap; at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:225)

----------

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.filterKeys(Lcom/google/common/collect/SetMultimap;Lcom/google/common/base/Predicate;)Lcom/google/common/collect/SetMultimap;

at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:225)

at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139)

at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121)

at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159)

at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:820)

at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:434)

at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4099)

at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1689)

at com.google.devtools.j2objc.TranslationProcessor.processAnnotations(TranslationProcessor.java:175)

at com.google.devtools.j2objc.TranslationProcessor.processFiles(TranslationProcessor.java:118)

at com.google.devtools.j2objc.J2ObjC.main(J2ObjC.java:197)


confile

unread,
Mar 31, 2015, 7:27:27 PM3/31/15
to j2objc-...@googlegroups.com
@Tom I read a lot of your other posts on Dagger2. I tested another thing. First I executed the annotation processor to generate the .java files in my build/sources/apt/ folder. This folder contains two files after generation: 

ApplicationModule$$ProvideTesterFactory.java
Dagger_ApplicationComponent.java

The source files are: 

-----------------

package com.example;


import javax.inject.Singleton;


import dagger.Module;

import dagger.Provides;


@Module

public class ApplicationModule {


@Provides

@Singleton

Tester provideTester() {

return new TesterImpl();

}

}

----------------

and

-----------------

package com.example;


import javax.inject.Singleton;


import dagger.Component;



@Component(modules = {ApplicationModule.class})

@Singleton

public interface ApplicationComponent {


Tester getTester();

}

----------------


Then I just skipped the annotation process and translated the files with j2objc: 

j2objc --no-package-directories -use-arc -d build/classes -sourcepath src/main/java:build/source/apt src/main/java/com/example/Tester.java src/main/java/com/example/TesterImpl.java src/main/java/com/example/SomeClassB.java src/main/java/com/example/ApplicationModule.java src/main/java/com/example/ApplicationComponent.java src/main/java/com/example/Starter.java build/source/apt/com/example/Dagger_ApplicationComponent.java 'build/source/apt/com/example/ApplicationModule$$ProvideTesterFactory.java' -classpath lib/javax.inject-1.jar:lib/dagger-2.0-SNAPSHOT.jar


Do I have to translate all generated files or just: Dagger_ApplicationComponent.java? What about: ApplicationModule$$ProvideTesterFactory.java 

The result is that 8 files have been translated. As seen in the following screenshot:


When I do the same with the javac command I get 10 .class files generated: 


Javac generated Dagger_ApplicationComponent$1.class and Dagger_ApplicationComponent$Builder.class . Did I make anything wrong here? 




 

Tom Ball

unread,
Mar 31, 2015, 9:22:33 PM3/31/15
to j2objc-...@googlegroups.com
The "missing" inner classes are declared in outerclass.h and implemented in outerclass.m. So the equivalent class for Dagger_ApplicationComponent$1, for example, is Dagger_ApplicationComponent_$1 in Dagger_ApplicationComponent.h.

I can't help you further with this issue. You have created a very complex build (note the number of classpath entries) which I can't replicate. j2objc annotation processing is simple:
  • Check the classpath for annotation processors.
  • If any exist, run the Eclipse APT batch compiler with the specified classpath, sourcepath, and source file list to a temporary output directory.
  • Scan that output directory for any .java files and add them to the list of files to be translated.
So it sounds like your complex build has found a problem, likely in the Eclipse APT support. To workaround this, you can follow the same steps the translator does: run javac on the files that have annotations with processors to a new output directory. Then include any generated java sources with your app.

--

confile

unread,
Apr 1, 2015, 7:10:43 AM4/1/15
to j2objc-...@googlegroups.com
Hi Tom, 

thank you for your help. To make it simple I created a simple plain java project here: https://github.com/confile/j2objc-dagger

The project has to bash script files java-script.sh and j2objc-script.sh. When you execute then you see exactly the same error as I do. 

you suggested: 

"To workaround this, you can follow the same steps the translator does: run javac on the files that have annotations with processors to a new output directory. Then include any generated java sources with your app."

This is exactly what I do so far but it is not an elegant solution. I have used annotation processing in another project with google auto factory (the other question I posted). Annotation processing works great with google auto factory but here with dagger there seems to be a bug somewhere in j2objc.

I hope that my sample project helps you.

Michael
Reply all
Reply to author
Forward
0 new messages