Using Buck for building React Native apps

1,157 views
Skip to first unread message

Marius Bergmann

unread,
Oct 17, 2015, 6:10:37 PM10/17/15
to Buck
Hi!

Has anyone already succeeded in building React Native apps with Buck? I'm currently trying to do so, but I think I'm messing something up about dependencies. I already added the React Native aar, but now I'm struggling to pull in all of this aar's dependencies:


+--- com.android.support:appcompat-v7:23.0.1
|    \--- com.android.support:support-v4:23.0.1
|         \--- com.android.support:support-annotations:23.0.1
\--- com.facebook.react:react-native:0.12.+ -> 0.12.0
     +--- com.google.code.findbugs:jsr305:3.0.0
     +--- com.squareup.okhttp:okhttp:2.4.0
     |    \--- com.squareup.okio:okio:1.4.0 -> 1.5.0
     +--- org.webkit:android-jsc:r174650
     +--- com.facebook.fresco:fresco:0.6.1
     |    +--- com.facebook.fresco:drawee:0.6.1
     |    |    +--- com.facebook.fresco:fbcore:0.6.1
     |    |    \--- com.android.support:support-v4:21.0.3 -> 23.0.1 (*)
     |    +--- com.facebook.fresco:imagepipeline:0.6.1
     |    |    +--- com.nineoldandroids:library:2.4.0
     |    |    +--- com.facebook.fresco:fbcore:0.6.1
     |    |    +--- com.android.support:support-v4:21.0.3 -> 23.0.1 (*)
     |    |    \--- com.parse.bolts:bolts-android:1.1.4
     |    \--- com.facebook.fresco:fbcore:0.6.1
     +--- com.facebook.fresco:imagepipeline-okhttp:0.6.1
     |    +--- com.facebook.fresco:imagepipeline:0.6.1 (*)
     |    +--- com.squareup.okhttp:okhttp:2.3.0 -> 2.4.0 (*)
     |    \--- com.facebook.fresco:fbcore:0.6.1
     +--- com.fasterxml.jackson.core:jackson-core:2.2.3
     +--- com.squareup.okhttp:okhttp-ws:2.4.0
     |    \--- com.squareup.okhttp:okhttp:2.4.0 (*)
     +--- com.squareup.okio:okio:1.5.0
     \--- com.android.support:appcompat-v7:23.0.1 (*)



Is there some "easy" way for pulling in all the dependency binaries or will I have to download/copy/create a target for them one by one? Also, will it be sufficient to mirror the dependency tree in Buck targets?

Kind regards,
Marius

Martin Kosiba

unread,
Oct 19, 2015, 9:30:35 AM10/19/15
to Marius Bergmann, Buck, Krzysztof Magiera
Hi!
You could use `buck fetch` to pull the necessary dependencies from maven, but I don't know if you can avoid writing the targets for that yourself. It might be better to ask on the React Native mailing list. I've CC'd Krzysztof, who might have a better answer to your question.

Kind regards,
  Marcin

--
You received this message because you are subscribed to the Google Groups "Buck" group.
To unsubscribe from this group and stop receiving emails from it, send an email to buck-build+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marius Bergmann

unread,
Oct 28, 2015, 3:48:58 AM10/28/15
to Martin Kosiba, Buck, Krzysztof Magiera
I started by pulling down the dependencies manually, but although I'm including the react-native aar as an android_prebuilt_aar (which seems to be available at compile time, as everything compiles into an apk binary), I get a runtime crash because of missing RN classes. Is there something special to keep in mind when using aar's as dependencies?

Does the RN team use Buck at FB? Maybe I'd better ask on the RN mailing list or StackOverflow then.

Martin Kosiba

unread,
Oct 28, 2015, 8:17:26 AM10/28/15
to Marius Bergmann, Buck, Krzysztof Magiera
Hi!
It would be helpful if you could share a repro somewhere so we can have a
quick look at why the class isn't making its way to the APK. AARs should
'just work', but we don't use them too heavily internally so the odds of
there being a weird issue are slightly higher than for, say,
android_binary.
Is the missing RN class actually in the .aar? Are you using proguard and
accidentally stripping the class?
Internally we build RN from source, so the flow is different. I don't
think asking on the RN list would hurt though :)

Kind regards,
Martin

Marius Bergmann

unread,
Oct 28, 2015, 8:38:35 PM10/28/15
to Martin Kosiba, Buck, Krzysztof Magiera
Hi Martin,

thank you for helping out!

> It would be helpful if you could share a repro somewhere so we can have a
> quick look at why the class isn't making its way to the APK.

I did a `react-native init` and then replaced gradle with buck in https://github.com/mbrgm/react-native-buck-example. The README has some instructions; the only part, which could be of importance, is that I used the local Android support repository for pulling in appcompat-v7 etc. via remote_file().

> Is the missing RN class actually in the .aar? Are you using proguard and
> accidentally stripping the class?

I checked using `jar tvf classes.jar` and it seems to be included. As I'm building with 'debug', proguard should not be used at all, should it?

> Internally we build RN from source, so the flow is different. I don't
> think asking on the RN list would hurt though :)

Let me know if you can help using the repro I supplied; if it's too time-consuming for you, just let me know and I will ask on the RN list. I didn't want to cross-post before I'm sure it's not a trivial mistake, which comes from my limited knowledge of buck. :)



I checked against different emulator versions (Genymotion). With the 'Google Nexus 4 API 16', the errors seem to come from this portion

```
E/SocketStream( 360): readFully was waiting for 285368 bytes, got 16192
E/SocketStream( 360): readFully was waiting for 269176 bytes, got 16192
E/SocketStream( 360): readFully was waiting for 252984 bytes, got 16192
E/SocketStream( 360): readFully was waiting for 236792 bytes, got 16192
```

while when using 'Google Nexus 4 API 22', the problem seems to come from the missing class I already mentioned:

```
E/AndroidRuntime( 2006): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.react.views.image.ReactImageView" on path: DexPathList[[zip file "/data/app/com
.example-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example-2/lib/x86, /vendor/lib, /system/lib]]
```

Thank you Martin!

Marius

Martin Kosiba

unread,
Oct 29, 2015, 2:41:12 PM10/29/15
to Marius Bergmann, Buck, Krzysztof Magiera
Hi Marius,
I quickly tried this and on my device (Nexus 5, have you tried a real
device, btw?) the app loads but displays a 'Unable to download JS bundle'
error. I don't have time to play around with installing the full RN stack
to investigate further, however I didn't get any of the class load errors
you described and doing a dexdump on the apk shows that the class is in
there.I did change the android libraries versions from 23.0.1 to 23.0.0
(as I had those available, shouldn't matter though). The github project
BUCK file seems fine, there are no obvious errors, it's not using
split-mode or anything crazy. It might make sense to ask on the RN mailing
list at this point.

Kind regards,
Martin
Reply all
Reply to author
Forward
0 new messages