react-native-cookies icon indicating copy to clipboard operation
react-native-cookies copied to clipboard

Import libraries to android "rnpm link"

Open icnz opened this issue 7 years ago • 13 comments

在windows使用react-native0.43.2开发app 按照说明操作了所有准备工作,但是在代码中引用时,报错了。 引用方式: import {CookieManager} from 'react-native-cookies'; 模拟器错误: Import libraries to android "rnpm link" index.android.bundle?platform=android&dev=true&hot=false&minify=false:58178:14 loadModuleImplementation index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12 guardedLoadModule index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36 _require index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77 index.android.bundle?platform=android&dev=true&hot=false&minify=false:1242:34 loadModuleImplementation index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12 guardedLoadModule index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36 _require index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77 index.android.bundle?platform=android&dev=true&hot=false&minify=false:1232:97 loadModuleImplementation index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12 guardedLoadModule index.android.bundle?platform=android&dev=true&hot=false&minify=false:63:45 _require index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77 global code index.android.bundle?platform=android&dev=true&hot=false&minify=false:62380:9

cmd错误: SyntaxError: Unexpected end of JSON input at parse () at process._tickCallback (internal/process/next_tick.js:109:7) { Error: write EPIPE at exports._errnoException (util.js:1033:11) at Socket._writeGeneric (net.js:727:26) at Socket._write (net.js:746:8) at doWrite (_stream_writable.js:329:12) at writeOrBuffer (_stream_writable.js:315:5) at Socket.Writable.write (_stream_writable.js:241:11) at Socket.write (net.js:673:40) at Socket.Writable.end (_stream_writable.js:475:10) at Socket.end (net.js:443:31) at Promise.resolve.then.then.then.catch.then.message (E:\workspace\NodeJsProject\react-native\react-native-navigation-example\node_modules\react-native\packager\src\Server\symbolicate\worker.js:35:33) code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }

icnz avatar Apr 21 '17 03:04 icnz

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.

Kaybarax avatar May 10 '17 09:05 Kaybarax

Same Issue..!

iiitmahesh avatar May 20 '17 10:05 iiitmahesh

@Kaybarax Did sloved that issue or any workaround???

iiitmahesh avatar May 22 '17 11:05 iiitmahesh

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.

Kaybarax avatar May 23 '17 05:05 Kaybarax

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 avatar Jun 14 '17 16:06 XDTZ

@XDTZ @Kaybarax solution works for me.

iiitmahesh avatar Jun 14 '17 19:06 iiitmahesh

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 avatar Jun 15 '17 16:06 XDTZ

@XDTZ Is the issue solved?

UnknownMi avatar Jun 29 '17 03:06 UnknownMi

@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:

  1. In project root yarn add react-native-cookies
  2. 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'
  1. 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')  
}
...
  1. 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 avatar Jun 29 '17 04:06 XDTZ

@XDTZ It's working!Thanks!

UnknownMi avatar Jun 29 '17 05:06 UnknownMi

@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

jslok avatar Jul 04 '17 20:07 jslok

@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.

XDTZ avatar Jul 05 '17 06:07 XDTZ

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.

jslok avatar Jul 05 '17 07:07 jslok