Build Error Report & Solution for UNA Mobile App (Android)

Issue

Encountered a build error in my setup due to an incompatible type in MainActivity.java:

MainActivity.java:15: error: incompatible types: int cannot be converted to boolean SplashScreen.show

Solution

The issue was resolved by eliminating redundancies in the code. If anyone has alternative solutions, they are welcome to share.

Code Fix

Here’s my working implementation:

package com.una.android;


import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;


public class MainActivity extends ReactActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Show Splash Screen on start before calling super.onCreate()
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }


    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "una";
    }


    /**
     * Returns the instance of the {@link ReactActivityDelegate}. Here we use a utility
     * class {@link DefaultReactActivityDelegate} which allows you to easily enable Fabric and
     * Concurrent React (i.e. React 18) with two boolean flags.
     */
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new DefaultReactActivityDelegate(
            this,
            getMainComponentName(),
            // If you opted-in for the New Architecture, we enable the Fabric Renderer.
            DefaultNewArchitectureEntryPoint.getFabricEnabled(),
            // If you opted-in for the New Architecture, we enable Concurrent React (React 18).
            DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled()
        );
    }
}


Additional Security Exception

Another issue encountered:

java.lang.SecurityException: com.una.android: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts.

Recommended Fix

Modify AndroidManifest.xml to explicitly define the receiver:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"  package="com.una.android">


    <uses-permission android:name="android.permission.INTERNET" />


    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <receiver
        android:name="com.facebook.react.devsupport.DevSupportReceiver"
        android:exported="false" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="UNA.IO">
                <action android:name="android.intent.action.VIEW" />


                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />


                <data
                    android:scheme="https"
                    android:host="www.una.io" />
                <data
                    android:scheme="http"
                    android:host="www.una.io" />
        </intent-filter>
      </activity>
    </application>
</manifest>


Build & Run the App

To apply the changes, clean the build and restart:

cd android
./gradlew clean
cd ..
npx react-native run-android

Now it seems to work perfectly. More updates coming soon...

  • 1612
  • More
Replies (0)
Login or Join to comment.