Trying to open an Unity activity inside Android Studio yields android.content.res.Resources$NotFoundException: String resource ID #0x0

0

I imported an unity project to android studio because Android Studio has the app and menus and it's supposed to open the unity game. Importing the unity project had zero errors, I updated all the gradle files and manifests.

Im trying to open the Unity activity through an android studio activity using a button.

The error:

V/FA: onActivityCreated
E/ample.phonedue: Invalid ID 0x00000000.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.phoneduel, PID: 31572
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phoneduel/com.unity3d.player.UnityPlayerActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6718)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:348)
        at android.content.res.Resources.getString(Resources.java:441)
        at com.unity3d.player.UnityPlayer.GetGlViewContentDescription(Unknown Source:20)
        at com.unity3d.player.UnityPlayer.<init>(Unknown Source:214)
        at com.unity3d.player.UnityPlayerActivity.onCreate(UnityPlayerActivity.java:41)
        at android.app.Activity.performCreate(Activity.java:7144)
        at android.app.Activity.performCreate(Activity.java:7135)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6718) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
I/Process: Sending signal. PID: 31572 SIG: 9

This is the activity that calls the Unity activity: (Not calling from the main activity cause of Application.Quit() in unity)

package com.example.phoneduel;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import com.unity3d.player.UnityPlayerActivity;

public class middle extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_middle);

        Intent intent = new Intent(middle.this, UnityPlayerActivity.class);
        startActivity(intent);

    }
}

The Unity activity is an AAR file implemented to my project.

build.gradle of the app:

apply plugin: 'com.android.application'

apply plugin: 'com.google.gms.google-services'  // Google Services plugin

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.phoneduel"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(":unityLibrary-debug")
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.firebase:firebase-core:17.2.3' //Firebase
    implementation 'com.google.firebase:firebase-analytics:17.2.3' //Firebase
    implementation 'com.google.firebase:firebase-auth:19.3.0' //Firebase
    implementation 'com.google.firebase:firebase-database:19.2.1' //Firebase
    implementation 'com.google.firebase:firebase-storage:19.1.1' //Firebase
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'org.jetbrains:annotations-java5:15.0'
    api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}

I can't find a fix. Please help me.

java
android
android-studio
unity3d
asked on Stack Overflow Jun 3, 2020 by Ariel Demidov • edited Jun 3, 2020 by Bashir

1 Answer

0

After reading about stack traces I managed to understand that the resource that was missing was somehow related to

at com.unity3d.player.UnityPlayer.GetGlViewContentDescription(Unknown Source:20)

After looking up that line in google I simply understood that I had to add the following line to my strings xml inside values:

<string name="game_view_content_description" translatable="false">Game view</string>

Bingo Bongo Bango it worked!

answered on Stack Overflow Jun 3, 2020 by Ariel Demidov

User contributions licensed under CC BY-SA 3.0