com.share01.MainApplication cannot be cast to cl.json.ShareApplication

I created a test react-native project,but got error:
com.share01.MainApplication cannot be cast to cl.json.ShareApplication

steps:
1)react-native init share01
2)yarn add react-native-share
3)react-native link
4)copy the sample codes to replace index.js
5)react-native run-android and got error

react-native environment:
Environment:
OS: macOS High Sierra 10.13.2
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.52.0 => 0.52.0

so,what’s the error?

Thanks!

35183311-e198f35e-fe1e-11e7-80e6-f2e10a5a19d7

5 thoughts on “com.share01.MainApplication cannot be cast to cl.json.ShareApplication

  1. @ozmaat

    Try this:

    AndroidManifest.xml:

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="com.yourpackage.name.provider"
                android:grantUriPermissions="true"
                android:exported="false">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths" />
            </provider>
    

    MainApplication.java:

    Add an implementation to the MainApplication class

    import cl.json.ShareApplication;
    public class MainApplication extends Application implements ShareApplication, ReactApplication 
    

    Add an override

     @Override
         public String getFileProviderAuthority() {
                return "com.yourpackage.name.provider";
         }
    

    Notice that I’ve hard coded the package name, it wouldn’t work for me otherwise.

  2. Thanks @Mikoz93. It solved the xml error.

    I get a different error, I think it is related with the defining the right path for android.

    Failed to find configured root that contains /storage/emulated/0/Download/1517644516612.png

    I use a snapshot plugin, which saves png file at “/storage/emulated/0/Download”.

    I have tried different paths in filepaths.xml but yet to find the correct path to define.

    Anyone else faced a similar issue?

  3. I am stuck with same issue in Android version
    I am trying to share remote image

    RNFetchBlob.config({
        fileCache : true,
        appendExt : 'jpg'
    }).fetch('GET', url, {})
    .then((res) => {
        let uri = Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path();
        let shareOptions = {
            message: title,
            url: uri,
            type: "image/jpeg",
            subject: title
          }
        Share.open(shareOptions).catch((err) => { err && console.log(err); })
    });
    

    in version 1.0.23 a compilation error happens
    cannot find symbol import cl.json.ShareApplication;

    in latest version the app crashes with an error
    Missing android.support.FILE_PROVIDER_PATHS meta-data
    probably it requires some xml resource.
    But what kind of resource should be in my case for images saved in the app cache?

Comments are closed.

com.share01.MainApplication cannot be cast to cl.json.ShareApplication

I created a test react-native project,but got error:
com.share01.MainApplication cannot be cast to cl.json.ShareApplication

steps:
1)react-native init share01
2)yarn add react-native-share
3)react-native link
4)copy the sample codes to replace index.js
5)react-native run-android and got error

react-native environment:
Environment:
OS: macOS High Sierra 10.13.2
Node: 9.3.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.52.0 => 0.52.0

so,what’s the error?

Thanks!

35183311-e198f35e-fe1e-11e7-80e6-f2e10a5a19d7

6 thoughts on “com.share01.MainApplication cannot be cast to cl.json.ShareApplication

  1. @ozmaat

    Try this:

    AndroidManifest.xml:

    <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="com.yourpackage.name.provider"
                android:grantUriPermissions="true"
                android:exported="false">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/filepaths" />
            </provider>
    

    MainApplication.java:

    Add an implementation to the MainApplication class

    import cl.json.ShareApplication;
    public class MainApplication extends Application implements ShareApplication, ReactApplication 
    

    Add an override

     @Override
         public String getFileProviderAuthority() {
                return "com.yourpackage.name.provider";
         }
    

    Notice that I’ve hard coded the package name, it wouldn’t work for me otherwise.

  2. Thanks @Mikoz93. It solved the xml error.

    I get a different error, I think it is related with the defining the right path for android.

    Failed to find configured root that contains /storage/emulated/0/Download/1517644516612.png

    I use a snapshot plugin, which saves png file at “/storage/emulated/0/Download”.

    I have tried different paths in filepaths.xml but yet to find the correct path to define.

    Anyone else faced a similar issue?

  3. I am stuck with same issue in Android version
    I am trying to share remote image

    RNFetchBlob.config({
        fileCache : true,
        appendExt : 'jpg'
    }).fetch('GET', url, {})
    .then((res) => {
        let uri = Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path();
        let shareOptions = {
            message: title,
            url: uri,
            type: "image/jpeg",
            subject: title
          }
        Share.open(shareOptions).catch((err) => { err && console.log(err); })
    });
    

    in version 1.0.23 a compilation error happens
    cannot find symbol import cl.json.ShareApplication;

    in latest version the app crashes with an error
    Missing android.support.FILE_PROVIDER_PATHS meta-data
    probably it requires some xml resource.
    But what kind of resource should be in my case for images saved in the app cache?

  4. Pingback: diamond art

Comments are closed.