4

Since Google warned us to provide support to 64-bit architecture, I am migrating my existing Unity Project from version Unity 5.6.6f to Unity 2018.4.1f

Upon running my project app crashes with log,

2019-06-02 20:08:27.869 14987-14987/com.example.myapplication:unityplayer E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication:unityplayer, PID: 14987
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.UnityActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:165)
        at android.app.ActivityThread.main(ActivityThread.java:6375)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:347)
        at android.content.res.MiuiResources.getText(MiuiResources.java:97)
        at android.content.res.Resources.getString(Resources.java:393)
        at com.unity3d.player.UnityPlayer.a(Unknown Source)
        at com.unity3d.player.UnityPlayer.<init>(Unknown Source)
        at com.example.myapplication.UnityActivity.onCreate(UnityActivity.java:52)
        at android.app.Activity.performCreate(Activity.java:6845)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)

STEPS I HAVE DONE FROM MY END

I have created a new project in Unity 2018.4.1f and changed the scripting back-end configuration to IL2CPP to support 64-bit architecture.

Please see my configuration below.

enter image description here

I have changed the package name in Unity to that my Android app package name and exported the build.

After exporting, I have pasted the Library folder, Asset folder and JniLibs folder contents (which I got from exported Unity Android project) to my Android project respective folders.

My UnityActivity file in Android Studio Project,

package com.example.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.widget.FrameLayout;

import com.unity3d.player.UnityPlayer;

public class UnityActivity extends Activity {

    protected static UnityPlayer mUnityPlayer; // don't change the name of UnityPlayer.currentActivity variable; referenced from native code

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        getWindow().setFormat(PixelFormat.RGBX_8888); // <--- UnityPlayer.currentActivity makes xperia play happy
        mUnityPlayer = new UnityPlayer(this);

        setContentView(mUnityPlayer);

        FrameLayout cameraLayout = findViewById(R.id.unity_player_layout);
        cameraLayout.addView(mUnityPlayer.getView());
        mUnityPlayer.requestFocus();

    }

    @Override
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
    }

    // Quit Unity
    @Override
    protected void onDestroy() {
        if (mUnityPlayer != null) {
            mUnityPlayer.quit();
        }
        super.onDestroy();
    }

    // Pause Unity
    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("OnPause called");
        mUnityPlayer.pause();
    }

    // Resume Unity
    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("OnResume called");
        mUnityPlayer.resume();
    }

    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("Onstop called");
    }

    // Low Memory Unity
    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mUnityPlayer.lowMemory();
    }

    // Trim Memory Unity
    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
            mUnityPlayer.lowMemory();
        }
    }

    // UnityPlayer.currentActivity ensures the layout will be correct.
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mUnityPlayer.configurationChanged(newConfig);
    }

    // Notify Unity of the focus change.
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        mUnityPlayer.windowFocusChanged(hasFocus);
    }

    // For some reason the multiple keyevent type is not supported by the ndk.
    // Force event injection by overriding dispatchKeyEvent().
    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_MULTIPLE)
            return mUnityPlayer.injectEvent(event);
        return super.dispatchKeyEvent(event);
    }

    // Pass any events not handled by (unfocused) views straight to UnityPlayer
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        return mUnityPlayer.injectEvent(event);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return mUnityPlayer.injectEvent(event);
    }

    /*API12*/
    public boolean onGenericMotionEvent(MotionEvent event) {
        return mUnityPlayer.injectEvent(event);
    }

    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();

        UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mUnityPlayer.quit();
            }
        });

    }
}

Corresponding XML file,

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/unity_player_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</FrameLayout>

My AndroidManifest file looks like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.front.autofocus"
        android:required="false" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen.multitouch"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen.multitouch.distinct"
        android:required="false" />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

    <!-- Allows access to the flashlight -->
    <permission
        android:name="android.permission.FLASHLIGHT"
        android:permissionGroup="android.permission-group.HARDWARE_CONTROLS"
        android:protectionLevel="normal"
        android:required="false" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true">

        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />


        <activity
            android:name=".UnityActivity"
            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:process=":unityplayer"
            android:screenOrientation="landscape">
            <meta-data
                android:name="unityplayer.UnityActivity"
                android:value="true" />
            <meta-data
                android:name="unityplayer.ForwardNativeEventsToDalvik"
                android:value="true" />
        </activity>

        <!--
            To support devices using the TI S3D library for stereo mode we must
            add the following library.
            Devices that require this are: ODG X6
        -->
        <uses-library
            android:name="com.ti.s3d"
            android:required="false" /> <!-- To support the ODG R7 in stereo mode we must add the following library. -->
        <uses-library
            android:name="com.osterhoutgroup.api.ext"
            android:required="false" />

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Since, I am a native developer and knows little about Unity, any help to sort out this issue will be really helpful!

1 Answer 1

15

I have to add the below line to strings.xml file to get rid of the error!

<string name="game_view_content_description">Game view</string>
3
  • That fixed it for me too, can you explain why?
    – Chiptus
    Mar 22, 2020 at 15:44
  • 1
    Didn't know exact reason. Somehow, while exporting unity assets into Android studio, the above line is missing from Strings.xml file. I just exported a sample unity project as an android project and compared my project with it. Upon comparing line by line, came to know that this particular line is missing. Adding it sorted out the error for me. Mar 23, 2020 at 8:49
  • Reason might be simple.Unity expects a string called 'game_view_content_description' which they missed while bundling the app. So, we are getting resource not found exception. Adding it works! Jul 14, 2020 at 8:00

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.