Skip to content

Commit c1ca50f

Browse files
committed
add troubleshooting section
1 parent c11c643 commit c1ca50f

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Diff for: src/content/learn/howto/troubleshooting.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Troubleshooting
3+
---
4+
5+
If you are running into an issue, this section will help you resolve it. Here are some common issues and their solutions.
6+
7+
8+
## UI isn't working after build
9+
10+
If UI is working correctly in Editor, but it is not working after you build the application and try to run it in your target platform, this can be caused by one of the following:
11+
12+
#### You forgot to build UI code
13+
14+
You must build your React project to a single `.js` file for it to work in built project. Make sure to run `npm run build` in your React project. It will report the path to the generated files. Then go to Unity Editor and make sure the `ReactRenderer` component is referencing that file correctly.
15+
16+
#### You have an error in your code
17+
18+
Sometimes there are errors that don't happen in Editor, but happens when you are testing in the target platform. Please check the error logs to see if you have an error, and if it's related to ReactUnity, report it as a bug.
19+
20+
#### Issues caused by Code stripping
21+
22+
When building with IL2CPP, Unity will strip out unused code to make the build size smaller and faster. And because ReactUnity uses reflection to reach code, Unity cannot detect that code and will strip it away as well. You can read more about code stripping [here](https://docs.unity3d.com/Manual/ManagedCodeStripping.html).
23+
24+
The easy way to solve this is adding Preserve attribute to methods you use in your code:
25+
26+
```cs
27+
[UnityEngine.Scripting.Preserve]
28+
public void MyCode() {
29+
...
30+
}
31+
```
32+
33+
Another way is to add `[assembly: UnityEngine.Scripting.Preserve]` to anywhere in your code to prevent stripping in all of that assembly.
34+
35+
Unity can also strip unused engine code, but that code may be used by ReactUnity. The way to prevent that is by using a `link.xml` file. For example, you may use this `link.xml`file if you are using a VideoPlayer component:
36+
37+
```xml
38+
<linker>
39+
<assembly fullname="UnityEngine.VideoModule">
40+
<type fullname="UnityEngine.Video.VideoPlayer" preserve="all"/>
41+
</assembly>
42+
43+
<assembly fullname="Assembly-CSharp"/>
44+
45+
<assembly fullname="ReactUnity"/>
46+
</linker>
47+
```
48+
49+
#### It doesn't work in Android when minify is enabled
50+
51+
A `Custom Proguard File` must be created in the Project settings and add this code must be added:
52+
53+
```
54+
-keep class com.facebook.yoga.** { *; }
55+
```
56+
57+
See [this issue](https://github.com/ReactUnity/core/issues/111) for details.
58+

Diff for: src/sidebarLearn.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"title": "Using custom fonts",
4040
"path": "/learn/howto/fonts"
4141
},
42+
{
43+
"title": "Troubleshooting",
44+
"path": "/learn/howto/troubleshooting"
45+
},
4246
{
4347
"hasSectionHeader": true,
4448
"sectionHeader": "Misc"
@@ -62,4 +66,4 @@
6266
]
6367
}
6468
]
65-
}
69+
}

0 commit comments

Comments
 (0)