0

I have successfully generated Objc .m and .h files from my simplistic Dagger-2 code.

https://gist.github.com/OscarRyz/ffd976fcae9acf87dbe1

Now I'm trying to compile those file using j2objcc but the error message says it can't find .h for the the Dagger-2 classes:

j2objcc  -c  -I. `find app -name *.m`
In file included from app/DaggerSearchComponent.m:10:
./app/SearchInPage_Factory.h:10:10: fatal error: 'dagger/internal/Factory.h' file not found
#include "dagger/internal/Factory.h"
         ^
1 error generated.
app/SearchComponent.m:11:10: fatal error: 'dagger/Component.h' file not found
#include "dagger/Component.h"
         ^
1 error generated.
In file included from app/SearchInPage_Factory.m:8:
./app/SearchInPage_Factory.h:10:10: fatal error: 'dagger/internal/Factory.h' file not found
#include "dagger/internal/Factory.h"
         ^
1 error generated.
In file included from app/SearchInPage_MembersInjector.m:9:
./app/SearchInPage_MembersInjector.h:10:10: fatal error: 'dagger/MembersInjector.h' file not found
#include "dagger/MembersInjector.h"
         ^
1 error generated.
app/SearchModule.m:10:10: fatal error: 'dagger/Module.h' file not found
#include "dagger/Module.h"
         ^
1 error generated.
In file included from app/SearchModule_ProvideHostFactory.m:8:
./app/SearchModule_ProvideHostFactory.h:10:10: fatal error: 'dagger/internal/Factory.h' file not found
#include "dagger/internal/Factory.h"
         ^
1 error generated.
In file included from app/SearchModule_ProvideHttpClientFactory.m:9:
./app/SearchModule_ProvideHttpClientFactory.h:10:10: fatal error: 'dagger/internal/Factory.h' file not found
#include "dagger/internal/Factory.h"
         ^
1 error generated.

Question: Does this means that I need to have the library source code while generating the ObjC code so the .h for those could be generated as well?

OscarRyz
  • 196,001
  • 113
  • 385
  • 569

1 Answers1

2

Original answer from @tabll

Dagger isn't distributed with j2objc, so you have to build it yourself. To do so (requires Maven, described in the Building J2ObjC wiki):

git clone https://github.com/google/dagger.git
cd dagger
mvn install
j2objc -d build -classpath $J2OBJC_HOME/lib/javax-inject.jar -sourcepath core/src/main/java `find core/src/main/java -name *.java`
cd build
j2objcc -c -I. `find dagger -name *.m`
ar -r libdagger.a *.o

Notes: Specify J2OBJC_HOME either where your j2objc distribution was unzipped, or if you built j2objc, its dist directory. To test, "ls $J2OBJC_HOME/j2objc" should list the j2objc script.

These instructions generate the macosx architecture, useful when testing. The files need to be recompiled for each architecture you want to use -- the easiest way to do so is to create a static library project in Xcode, add the translated files, then include this project in your app and add it as a dependency of your app.

ar will warn that "libdagger.a(package-info.o) has no symbols", which can be ignored since it doesn't have any symbols.

Community
  • 1
  • 1
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
  • I am having issues with the mvn install command. It say: [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/gbemirojiboye/Downloads/j2objc-master/dagger). Please verify you invoked Maven from the correct directory. -> [Help 1] org.apache.maven.lifecycle.MissingProjectException: The goal you specified requires a project to execute but there is no POM in this directory (/Users/gbemirojiboye/Downloads/j2objc-master/dagger). Please verify you invoked Maven from the correct directory. What could be the problem here, please? – gbenroscience Aug 08 '18 at 01:43
  • @tabll J2Objc ran fine and generated my .m and .h files in the build_output folder. Then when I ran j2objcc on it, there were too many errors. So I decided to install dagger and see what happens... only to get the above errors during "mvn install" – gbenroscience Aug 08 '18 at 01:46