react-native-cookies
react-native-cookies copied to clipboard
Import libraries to android "rnpm link"
在windows使用react-native0.43.2开发app
按照说明操作了所有准备工作,但是在代码中引用时,报错了。
引用方式:
import {CookieManager} from 'react-native-cookies';
模拟器错误:
Import libraries to android "rnpm link"
cmd错误:
SyntaxError: Unexpected end of JSON input
at parse (
I'm also having the same issue. I think I'm gonna go for the approach of returning the Cookie as a string in part and parcel of the response string/json.
Same Issue..!
@Kaybarax Did sloved that issue or any workaround???
After linking the rnpm, you need to reload the whole app. I noticed that when you perform any linking that writes to your java classes, you might need to reload the entire app for it to pick the plugin.
I looked over every posts regarding this error here. Tried every tricks. Still no luck.
I would love to have someone confirm that this package works with [email protected] . Before that I'll just try wiggle around my issue for now.
@XDTZ @Kaybarax solution works for me.
After some experiments, I can confirm currently the package does work. I failed because I installed wix/[email protected] first, whose installation process requires editing many android project files, and it messed up the linking script for react-native-cookies.
@XDTZ Is the issue solved?
@UnknownMi Basically do not use rnpm link
. Install everything manually. I'm not sure why. It might be because the wix/react-native-navigation requires changing files into the format that rnpm
does not recognize. Or rnpm
and react-native link
being simply out-of-date or broken.
The following steps worked for me:
- In project root
yarn add react-native-cookies
- In android/settings.gradle, add 2 lines to include the package, the finished file looks like this:
rootProject.name = 'testing'
// *******add the following 2 lines /////////
include ':react-native-cookies'
project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')
include ':app'
- In android/app/build.gradle, add the project to compile dependencies:
...
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:25.3.1"
compile "com.facebook.react:react-native:+" // From node_modules
// ******add the following line ********//
compile project(':react-native-cookies')
}
...
- In android/app/src/main/java/com/
/MainApplication.java , add 2 lines:
... // some other java libraries imports
// *****add the package import *********//
import com.psykar.cookiemanager.cookiemanagerpackage;
public class MainApplication extends NavigationApplication {
...
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
// ... your package imports ... //
// ******** add the follow line of cookie package import. If being last line, take out the tail comma ***** //
new CookieManagerPackage(),
// ... your other package imports .. //
);
}
...
These manual installation process can be applied to many other packages involving java native codes.
Sometimes you need to uninstall the old build from the emulator/device and reinstall for this to work.
If you are on Windows, you might encounter errrors like Could not expand ZIP: ... react-native-navigation-release.aar
, you need to open the android project with Android Studio once and then run compile again.
If errors like Could not delete path...
pops out, just delete the said folder/file manuallly and run again.
Just reply if you bump into problem installing. It's working for me.
@XDTZ It's working!Thanks!
@XDTZ Thanks for your instructions but I ran into an issue after trying the manual install. I get this error when trying to run the app.
C:\Users\jlok\Documents\ig\android\app\src\main\java\com\ig\MainApplication.java:13: error: cannot find symbol
import com.psykar.cookiemanager.cookiemanagerpackage;
^
symbol: class cookiemanagerpackage
location: package com.psykar.cookiemanager
C:\Users\jlok\Documents\ig\android\app\src\main\java\com\ig\MainApplication.java:27: error: cannot find symbol
new CookieManagerPackage()
^
symbol: class CookieManagerPackage
2 errors
:app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
Any idea how to fix this? Thanks
@justinlok You need to make sure you've added the codes in settings.gradle and app/build.gradle as I said. If error persisted, try open the android folder with Android Studio and check the file to see if the console says anything useful to fix the problem.
I thought I did all of that right, but anyways I was able to fix the problem by using "react-native link react-native-cookies" instead of manually linking or using rnpm link.