0

我已经从简单的 Dagger-2 代码中成功生成了 Objc .m 和 .h 文件。

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

现在我正在尝试使用编译这些文件,j2objcc但错误消息说它找不到 Dagger-2 类的 .h:

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?

4

1 回答 1

2

@tabll原始答案

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) has no symbols”,可以忽略它,因为它没有任何符号。

于 2015-06-09T22:28:47.807 回答