Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger2 with J2Objc #4

Closed
confile opened this issue Feb 9, 2015 · 17 comments
Closed

Dagger2 with J2Objc #4

confile opened this issue Feb 9, 2015 · 17 comments

Comments

@confile
Copy link
Contributor

confile commented Feb 9, 2015

Did you make any progress on using Dagger2 with J2Objc?

I created a demo with made it work with GWT: https://github.com/confile/GWT-Dagger2-Demo

@brunobowden
Copy link
Contributor

Just finished getting Guava integrated and working. Inject is now added.
Now going through the dagger 2 examples. Hopefully I'll get something up
and running tomorrow. Also thanks for sharing your own demo.

On Sun Feb 08 2015 at 8:37:17 PM Confile notifications@github.com wrote:

Did you make any progress on using Dagger2 with J2Objc?

I created a demo with made it work with GWT:
https://github.com/confile/GWT-Dagger2-Demo


Reply to this email directly or view it on GitHub
https://github.com/brunobowden/j2objc-gradle/issues/4.

@confile
Copy link
Contributor Author

confile commented Feb 9, 2015

Just look at my example project it will save you a lot of time.

The only thing which is missing is adding the dagger2 jar to J2Objc. This must be done via classpath. I did not understood how to add multiple jars to the classpath using your gradle plugin.

If you did this I would be happy if you could post it to me.

Here you can see how to configure your build.gradle for dagger2.

Here is a simple dagger example you can copy and paste. Use it like this:

MyWidgetGinjector injector = Dagger_MyWidgetGinjector.create();
SomeService service = injector.getSomeService();

Hope this helps!

@confile
Copy link
Contributor Author

confile commented Feb 12, 2015

I manage to translate a simple project which included dagger2. Using javac and j2objc worked fine even with the generated classes from the Dagger Components. I mean the Dagger_....java files.

I created this pull request: https://github.com/brunobowden/j2objc-gradle/pull/10 so you can specify the source path of the annotation processor output.

Here is the configuration I use:

    translateFlags """--no-package-directories --prefixes prefixes.properties --mapping method-mappings.properties -use-arc -classpath ${projectDir}/lib/dagger-2.0-SNAPSHOT.jar"""

My generated files in build/source/apt are:

Dagger_MyWidgetGinjector.java
MyWidgetClientModule$$ProvideSomeServiceFactory.java

(Based on this project: https://github.com/confile/GWT-Dagger2-Demo)

Here is what I get while doing the translation:

error: /Users/mg/Documents/Grails/GGTS3.6.2/TestJ2Objc/build/source/apt/com/example/incrementer/shared/test2/Dagger_MyWidgetGinjector.java:26: MyWidgetClientModule$$ProvideSomeServiceFactory cannot be resolved to a type
translating /Users/mg/Documents/Grails/GGTS3.6.2/TestJ2Objc/build/source/apt/com/example/incrementer/shared/test2/MyWidgetClientModule$$ProvideSomeServiceFactory.java
Translated 8 files: 1 errors, 0 warnings

Do you have any idea what to do here? Thank for your help.

@confile
Copy link
Contributor Author

confile commented Feb 12, 2015

I should post my command line compile command as well. The following works perfect:

javac -d build/classes -sourcepath src/main/java:build/source/apt src/main/java/com/example/incrementer/shared/SomeEvent.java src/main/java/com/example/incrementer/shared/NumberIncrementer.java src/main/java/com/example/incrementer/shared/JSNIExample.java src/main/java/com/example/incrementer/shared/test2/SomeService.java src/main/java/com/example/incrementer/shared/test2/SomeServiceImpl.java src/main/java/com/example/incrementer/shared/test2/MyWidgetClientModule.java src/main/java/com/example/incrementer/shared/test2/MyWidgetGinjector.java build/source/apt/com/example/incrementer/shared/test2/Dagger_MyWidgetGinjector.java -classpath lib/dagger-2.0-SNAPSHOT.jar:lib/javax.inject-1.jar

The generated file MyWidgetClientModule$$ProvideSomeServiceFactory.java is also compiled although I did not explicitly call ed it in the javac command. When I put this file in the javac classpath then I get an error

javac: file not found: build/source/apt/com/example/incrementer/shared/test2/MyWidgetClientModule55781ProvideSomeServiceFactory.java

I guess this is because of you $ sign. May be this causes you plugin to fail to translate too?

@confile
Copy link
Contributor Author

confile commented Mar 4, 2015

@brunobowden Did you make any progress on this issue?

@jonnolen
Copy link

jonnolen commented Mar 4, 2015

I haven't done any additional work on this gem, and have no immediate
plans. We have ended up abandoning j2objc for our current project.

On Wed, Mar 4, 2015 at 10:15 AM, Confile notifications@github.com wrote:

@brunobowden https://github.com/brunobowden Did you make any progress
on this issue?


Reply to this email directly or view it on GitHub
https://github.com/brunobowden/j2objc-gradle/issues/4#issuecomment-77175608
.

@confile
Copy link
Contributor Author

confile commented Mar 4, 2015

And what about you @brunobowden ?

@brunobowden
Copy link
Contributor

Hi @confile. I'm busy with some higher priority work right now and
attending the TED conference next week. I'll likely to return to this after
that, in about two weeks tiem.

On Wed, Mar 4, 2015 at 7:53 AM Confile notifications@github.com wrote:

And what about you @brunobowden https://github.com/brunobowden ?


Reply to this email directly or view it on GitHub
https://github.com/brunobowden/j2objc-gradle/issues/4#issuecomment-77183702
.

@confile
Copy link
Contributor Author

confile commented Mar 30, 2015

@brunobowden Hi Bruno, did you make any progress o this issue?

@confile
Copy link
Contributor Author

confile commented Apr 4, 2015

@brunobowden This is a j2objc issue see google/j2objc#510 (comment)

@confile confile closed this as completed Apr 4, 2015
@confile confile reopened this Apr 4, 2015
@confile
Copy link
Contributor Author

confile commented Apr 4, 2015

I reopened this issue because translation still raises error. See google/j2objc#513

@confile
Copy link
Contributor Author

confile commented Apr 7, 2015

@brunobowden I still struggling with this issue and I need help. Translating dagger and linking to Xcode works fine using the following configuration:

translateFlags """--no-package-directories --prefixes prefixes.properties -use-arc --doc-comments --build-closure
        -classpath ${projectDir}/lib/auto-factory-0.1-beta1.jar:${projectDir}/lib/auto-service-1.0-rc1.jar:${projectDir}/lib/guava-16.0.jar:${projectDir}/lib/javawriter-2.4.0.jar:${projectDir}/lib/dagger-1.2.0.jar"""

translateSourcepaths "${projectDir}/libSrc/javax.inject-1-sources.jar:${projectDir}/libSrc/dagger-2.0-SNAPSHOT-sources.jar"

The only problem is that transpiling gives the following warning:

warning: could not find source path for dagger.Provides.Type

If I linke my translated files with Xcode I get the following compiler error:

clang: error: no such file or directory: '/Users/mg/Documents/Grails/GGTS3.6.2/TestJ2Objc/build/j2objc/ApplicationModule$ProvideSomeClassXFactory.m'
clang: error: no input files

If I do not use the @Provides annotation from dagger2 I can build in Xcode without problems.

Here is the code I use:

package com.example;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;




@Module
public class ApplicationModule {

    @Provides
    @Singleton
    SomeClassX provideSomeClassX() {
        return new SomeClassX();
    }
}

and

package com.example;

import dagger.Provides;

public class SomeClassX {
}

If you could solve this last part of the puzzle, then we are done.

@confile
Copy link
Contributor Author

confile commented Apr 9, 2015

Here is the latest open issue: google/j2objc#517

@brunobowden
Copy link
Contributor

@confile - excellent writeup on the bug, thanks for taking the time to do
that properly

On Thu, Apr 9, 2015 at 2:33 PM Confile notifications@github.com wrote:

Here is the latest open issue: google/j2objc#517
google/j2objc#517


Reply to this email directly or view it on GitHub
https://github.com/brunobowden/j2objc-gradle/issues/4#issuecomment-91361935
.

@confile
Copy link
Contributor Author

confile commented Apr 10, 2015

@brunobowden Well I would need a little help on this issue.

@confile
Copy link
Contributor Author

confile commented Apr 10, 2015

@brunobowden How do you deal with java files generated with annotation processor which contains $$

@confile
Copy link
Contributor Author

confile commented Apr 13, 2015

@brunobowden This is fixed with my latest pull request.

@confile confile closed this as completed Apr 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants