wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.6k stars 553 forks source link

Android: Native component for "RCTPdf" does not exist #146

Closed embpdaniel closed 6 years ago

embpdaniel commented 6 years ago

I saw this issue was reported before, but I'm not able to resolve it. I am using react-native-pdf 3.0.4. I already was using react-native-fetch-blob (version 0.10.8), so I did not link it again, since it's already linked and working fine. I have this setup:

android/settings.gradle

rootProject.name = 'MyApp'
include ':react-native-image-resizer'
project(':react-native-image-resizer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-resizer/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':react-native-background-timer'
project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')
include ':react-native-fast-image'
project(':react-native-fast-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fast-image/android')
include ':react-native-sensitive-info'
project(':react-native-sensitive-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sensitive-info/android')
include ':react-native-prompt-android'
project(':react-native-prompt-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-prompt-android/android')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-background-geolocation'
project(':react-native-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-geolocation/android')
include ':react-native-background-upload'
project(':react-native-background-upload').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-upload/android')
include ':react-native-sqlite-storage'
project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android')
include ':react-native-hockeyapp', ':app'
project(':react-native-hockeyapp').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-hockeyapp/android')
include ':detox'
project(':detox').projectDir = new File(rootProject.projectDir, '../node_modules/detox/android/detox')
include ':react-native-directed-scrollview'
project(':react-native-directed-scrollview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-directed-scrollview/android')
include ':react-native-fetch-blob'
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')
include ':react-native-cookies'
project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')
include ':react-native-pdf'
project(':react-native-pdf').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pdf/android')

include ':app'

android/app/build.gradle (dependencies)

dependencies {
    compile project(':react-native-image-resizer')
    compile 'com.facebook.fresco:animated-gif:1.3.0'
    compile 'com.facebook.fresco:animated-webp:1.3.0'
    compile 'com.facebook.fresco:webpsupport:1.3.0'
    compile 'com.facebook.fresco:webpsupport:1.3.0'
    compile project(':react-native-fetch-blob')
    compile project(':react-native-cookies')
    compile project(':react-native-image-picker')
    compile project(':react-native-config')
    compile project(':react-native-fast-image')
    compile project(':react-native-sensitive-info')
    compile project(':react-native-prompt-android')
    compile project(':react-native-sqlite-storage')
    compile project(':react-native-splash-screen')
    compile project(':react-native-background-geolocation')
    compile project(':react-native-background-upload')
    compile project(":react-native-hockeyapp")
    compile project(':react-native-background-timer')
    compile project(':react-native-directed-scrollview')
    compile(project(':react-native-device-info')) {
      exclude group: 'com.google.android.gms'
    }
    compile project(':react-native-pdf')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile(name: 'tslocationmanager', ext: 'aar')

    androidTestImplementation(project(path: ":detox"))
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test:rules:1.0.1'
}

MainApplication.java (imports)

import android.app.Application;

import com.facebook.react.ReactApplication;
import org.wonday.pdf.RCTPdfView;
import fr.bamlab.rnimageresizer.ImageResizerPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.imagepicker.ImagePickerPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.dylanvann.fastimage.FastImageViewPackage;
import br.com.classapp.RNSensitiveInfo.RNSensitiveInfoPackage;
import im.shimo.react.prompt.RNPromptPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import com.transistorsoft.rnbackgroundgeolocation.RNBackgroundGeolocation;
import com.vydia.RNUploader.UploaderReactPackage;
import org.pgsqlite.SQLitePluginPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.slowpath.hockeyapp.RNHockeyAppModule;
import com.slowpath.hockeyapp.RNHockeyAppPackage;
import com.ocetnik.timer.BackgroundTimerPackage;
import com.rnds.DirectedScrollViewPackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import com.psykar.cookiemanager.CookieManagerPackage;

import java.util.Arrays;
import java.util.List;

MainApplication.java (getPackages)

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new ImageResizerPackage(),
            new RNDeviceInfo(),
            new ImagePickerPackage(),
            new ReactNativeConfigPackage(),
            new FastImageViewPackage(),
            new RNSensitiveInfoPackage(),
            new RNPromptPackage(),
            new SplashScreenReactPackage(),
            new RNBackgroundGeolocation(),
            new BackgroundTimerPackage(),
            new UploaderReactPackage(),
            new SQLitePluginPackage(),
            new DirectedScrollViewPackage(),
            new RNFetchBlobPackage(),
            new RCTPdfView(),
            new RNHockeyAppPackage(MainApplication.this),
            new CookieManagerPackage()
      );
    }

React Native Component

import Pdf from 'react-native-pdf';
.......
render(){
return (
    <View>
        <Pdf style={styles.pdf} source={{ uri: 'http://somepdflink/file.pdf', cache: true }} onError={this._onError} />
    </View>
)
}

Did I miss some configuration? I think I have everything but it somehow throws the error. Any help appreciated, thanks.

embpdaniel commented 6 years ago

I also tried deleting caches with: watchman watch-del-all && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache

And uninstalling the app completely and reinstalling. No luck :(

embpdaniel commented 6 years ago

Don't know what happened, but after uninstalling it completely, then going back to it to give it one more try, I set it up exactly as I did before, and this time it worked. Go figure ¯_(ツ)_/¯