google / j2objc

A Java to iOS Objective-C translation tool and runtime.
http://j2objc.org
Apache License 2.0
5.99k stars 968 forks source link

Files with same name #2238

Closed msnazarow closed 11 months ago

msnazarow commented 11 months ago

By java code contains files with same names located in different packages. Is there a way to proper generater objc code in that case?

tomball commented 11 months ago

The javac tools converts the package into a relative directory when generating classfiles, so for example, java.util.Date causes the java/util/Date.class classfile to be generated. This way, java.sql.Date won't overwrite it, because it gets written to java/sql/Date.class. By default, j2objc follows the same pattern, so java/util/Date.h won't be overwritten by java/sql/Date.h.

A few beginning j2objc users wanted a simpler pattern, so the --no-package-directories flag was added, which would cause those two files to be written to the same path. We don't recommend using this flag (it's really only for hello-world level example apps). So this works as designed, and if you are using this flag and having this problem, either rename one of the classes or use a build system that supports relative paths for output files.

In the future, if you have questions, please ask them on https://stackoverflow.com/ with the #j2objc tag. Issues are normally used to report bugs and make enhancement suggestions.

msnazarow commented 11 months ago

@tomball Yes, the issue with directories is that header path that j2obj generates is full. And if i whant to use Cocoapods, and i stell have files with same names (even in different directories) - it won't compile until i use separate targets. And just because every directory can have file with the same name, so i need target(Podspec) for each directory and it becomes hell.

So my real question was how to generate files with different names no matter what directories they located in

tomball commented 11 months ago

The general way to fix issues like this is to break a step like this into smaller tasks. One way to do this here is to run j2objc with a temporary output directory, then copy and or rename the generated files as you need to.

This isn’t something easily addressed in the j2objc compiler itself because it’s a normal Java compiler following normal Java build conventions (its front end is actually javac). It’s used to transpile literally millions of Java lines by apps expecting it to continue behaving the way it currently does.

That said, it’s also open-source, so you are welcome to fork it to do whatever best suits your needs.

On Sun, Nov 19, 2023 at 12:06 AM Михаил Назаров @.***> wrote:

@tomball https://github.com/tomball Yes, the issue with directories is that header path that j2obj generates is full. And if i whant to use Cocoapods, and i stell have files with same names (even in different directories) - it won't compile until i use separate targets. And just because every directory can have file with the same name, so i need target(Podspec) for each directory and it becomes hell.

So my real question was how to generate files with different names no matter what directories they located in

— Reply to this email directly, view it on GitHub https://github.com/google/j2objc/issues/2238#issuecomment-1817769203, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW2JL7QUBWHMUYODA3LMLDYFGVZDAVCNFSM6AAAAAA7Q5XY5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJXG43DSMRQGM . You are receiving this because you were mentioned.Message ID: @.***>