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

Generated .m file containing $$ in its name are not found in Xcode (J2objc 0.9.7) #517

Closed
confile opened this issue Apr 9, 2015 · 9 comments

Comments

@confile
Copy link

confile commented Apr 9, 2015

When Java files contain $$ in there name Xcode raises an error because it searches for files containing only $ in its name, i.e., one dollar sign instead of two.

I use the J2objc 0.9.7. Here is a simple example of the problem. Create two files:

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

public class SomeClassX {
}

Here are the steps to reproduce:

  1. Create the .java files with annotation processing with
javac -d build/classes -sourcepath src/main/java src/main/java/com/example/SomeClassX.java src/main/java/com/example/ApplicationModule.java -classpath lib/dagger-compiler-2.0-20150330.203231-18-jar-with-dependencies.jar

This will create the class files as well as build/classes/com/example/ApplicationModule$$ProvideSomeClassXFactory.java.
2. Execute j2objc:

j2objc --no-package-directories -use-arc --build-closure -d build/classes -sourcepath src/main/java:libSrc/javax.inject-1-sources.jar:libSrc/dagger-2.0-sources.jar src/main/java/com/example/SomeClassX.java src/main/java/com/example/ApplicationModule.java build/classes/com/example/'ApplicationModule$$ProvideSomeClassXFactory.java'

this will generate the following 18 files:
classes
3. Insert the generated files in a Xcode project and build the project with other linker flag -ObjC -lguava -ljavax_inject -ljre_emul -ljsr305

Step 3 will generate the following error:

test111_xcodeproj

no such file or directory: ApplicationModule$ProvideSomeClassXFactory.m

The correct file must contain two dollar signs instead of one. It seems that the transpiling went wrong in the case of two dollar signs in their name.

@confile
Copy link
Author

confile commented Apr 9, 2015

I created a sample project to reproduce this issue here: https://github.com/confile/j2objc-dollarsign

@tomball
Copy link
Collaborator

tomball commented Apr 9, 2015

Xcode uses $ for macros, and apparently $$ for a $ constant. That's why the filename only has one $ in the error message. Try changing the names ApplicationModule$$$$ProvideSome... If that doesn't work, ask on StackOverflow where Xcode experts may help.

@tomball tomball closed this as completed Apr 9, 2015
@confile
Copy link
Author

confile commented Apr 10, 2015

@tomball The problem is that the dagger annotation processor generates these files with $$ in the middle so I cannot change them.

@tomball
Copy link
Collaborator

tomball commented Apr 10, 2015

It looks like you found an Xcode bug: where it can't build source files
with $ in their names. You need to file a bug with Apple, then find some
workaround for your project until Apple fixes this. One option is to create
a static library using Make or some other build tool, then link your app
with that library in Xcode. Or come up with some other idea, since that's
what software engineers do.

On Fri, Apr 10, 2015 at 12:08 AM Confile notifications@github.com wrote:

@tomball https://github.com/tomball The problem is that the dagger
annotation processor generates these files with $$ in the middle so I
cannot change them.


Reply to this email directly or view it on GitHub
#517 (comment).

@tomball
Copy link
Collaborator

tomball commented Apr 10, 2015

Another option you have (which would be faster than waiting for an Xcode
fix) is to fork Dagger and change its annotation processor to use something
different than $$ in their generated class names. It should be a one-line
change, and if you submit a pull request that team might include it in the
next release.

On Fri, Apr 10, 2015 at 6:50 AM Tom Ball tball@google.com wrote:

It looks like you found an Xcode bug: where it can't build source files
with $ in their names. You need to file a bug with Apple, then find some
workaround for your project until Apple fixes this. One option is to create
a static library using Make or some other build tool, then link your app
with that library in Xcode. Or come up with some other idea, since that's
what software engineers do.

On Fri, Apr 10, 2015 at 12:08 AM Confile notifications@github.com wrote:

@tomball https://github.com/tomball The problem is that the dagger
annotation processor generates these files with $$ in the middle so I
cannot change them.


Reply to this email directly or view it on GitHub
#517 (comment).

@confile
Copy link
Author

confile commented Apr 10, 2015

@tomball I have a much simpler solution. You can simple duplicate files like this. When you have a file x$$y.* you make a copy and name it x$y.* This way xcode will find the correct file.

@tomball
Copy link
Collaborator

tomball commented Apr 10, 2015

Here's an even simpler solution: use the latest Dagger 2.0 -- they recently
changed the delimiter they use:

google/dagger@1f70d57

If you have problems with sources generated by annotation processors in the
future, please work with the teams that support those processors. The
Dagger team might have fixed this issue when you first found it, if you had
only asked them.

On Fri, Apr 10, 2015 at 7:41 AM Confile notifications@github.com wrote:

@tomball https://github.com/tomball I have a much simpler solution. You
can simple duplicate files like this. When you have a file x$$y.* you
make a copy and name it x$y.* This way xcode will find the correct file.


Reply to this email directly or view it on GitHub
#517 (comment).

@confile
Copy link
Author

confile commented Apr 10, 2015

@tomball Thank you tom you are brilliant. From our previous discussion I think I need your latest version of guava 18, since dagger needs at least 18. As we discussed earlier using dagger annotation processor directly with j2objc will only work after your guava update. Can you guess when this update will come?

Thank you so much for your help.

@tomball
Copy link
Collaborator

tomball commented Apr 10, 2015

We're in the process of using jarjar https://code.google.com/p/jarjar/ to
repackage the translator so its use of Guava doesn't conflict with other
versions. Until that's complete, you'll need to use javac to do annotation
processing, then translate all .java files found in the output directory. I
assume you're already doing that, since blocking one's project waiting on
any open-source project's bug fix is never advised.

On Fri, Apr 10, 2015 at 9:06 AM Confile notifications@github.com wrote:

@tomball https://github.com/tomball Thank you tom you are brilliant.
From our previous discussion I think I need your latest version of guava
18, since dagger needs at least 18. As we discussed earlier using dagger
annotation processor directly with j2objc will only work after your guava
update. Can you guess when this update will come?

Thank you so much for your help.


Reply to this email directly or view it on GitHub
#517 (comment).

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

2 participants