我已经从我简单的Dagger-2代码中成功生成了Objc .m和.h文件。
https://gist.github.com/OscarRyz/ffd976fcae9acf87dbe1
现在我正在尝试使用j2objcc
编译这些文件,但错误消息显示它找不到.h用于Dagger-2类:
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.
问题:这是否意味着我需要在生成ObjC代码时拥有库源代码,以便为这些代码生成.h?
答案 0 :(得分:1)
Dagger并没有与j2objc一起发布,所以你必须自己构建它。为此(需要Maven,在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
注意: 指定J2OBJC_HOME,或者解压缩j2objc发行版,或者构建j2objc,即dist目录。要测试," ls $ J2OBJC_HOME / j2objc"应列出j2objc脚本。
这些指令生成macosx架构,在测试时非常有用。需要为要使用的每个体系结构重新编译文件 - 最简单的方法是在Xcode中创建一个静态库项目,添加已翻译的文件,然后在您的应用程序中包含此项目并将其添加为依赖项你的应用。
ar会警告" libdagger.a(package-info.o)没有符号",可以忽略它,因为它没有任何符号。