Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crash when add line to MainApplication.Java #16

Closed
3 tasks
websasindu opened this issue May 4, 2021 · 4 comments
Closed
3 tasks

App crash when add line to MainApplication.Java #16

websasindu opened this issue May 4, 2021 · 4 comments

Comments

@websasindu
Copy link

websasindu commented May 4, 2021

Environment

Please provide the following information about your environment:

  1. Development OS: Windows
  2. Device OS & Version: Windows 10
  3. Version: ViroReact 2.20.2 and React Native 0.63.4
  4. Device(s): Google Pixel 4

Description

I am making new ar ar using this viro library and i did all config

app\src\main\build.gradle

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

implementation project(':gvr_common')
implementation project(':arcore_client')
implementation project(path: ':react_viro')
implementation project(path: ':viro_renderer')
implementation 'com.google.android.exoplayer:exoplayer:2.7.1'
implementation 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-7'

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
  exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
}

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
    implementation jscFlavor
}

}

app\build.gradle

buildscript {
ext {
buildToolsVersion = "29.0.2"
minSdkVersion = 24
compileSdkVersion = 29
targetSdkVersion = 29
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:4.1.1')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<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-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" tools:replace="required"/>
<uses-feature android:glEsVersion="0x00030000" android:required="false" tools:node="remove" tools:replace="required" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false" tools:replace="required" />
<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="false" tools:replace="required" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:usesCleartextTraffic="true"
  android:theme="@style/AppTheme">
    <meta-data android:name="com.google.ar.core" android:value="required" />
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    android:launchMode="singleTask"
    android:usesCleartextTraffic="true"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
      <category android:name="com.google.intent.category.CARDBOARD" />
      <category android:name="com.google.intent.category.DAYDREAM" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

MainApplication.java

package com.myviroapp;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.viromedia.bridge.ReactViroPackage;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@OverRide
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
        packages.add(new ReactViroPackage(ReactViroPackage.ViroPlatform.valueOf("AR")));
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

@OverRide
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}

@OverRide
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}

/**

  • Loads Flipper in React Native templates. Call this in the onCreate method with something like
  • initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  • @param context
  • @param reactInstanceManager
    /
    private static void initializeFlipper(
    Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
    try {
    /

    We use reflection here to pick up the class that initializes Flipper,
    since Flipper library is not available in release mode
    */
    Class<?> aClass = Class.forName("com.myviroapp.ReactNativeFlipper");
    aClass
    .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
    .invoke(null, context, reactInstanceManager);
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (NoSuchMethodException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    e.printStackTrace();
    }
    }
    }
    }

Everything looks fine.but when i add packages.add(new ReactViroPackage(ReactViroPackage.ViroPlatform.valueOf("AR")));

into mainapplication.java file app crashed and when i remove it app running normaly but i got error message Ui manage not found. so what i have to do for solve this issue. Thank you

@bilewinters
Copy link
Contributor

Hello! Have you tried building and running our starter-kit app?

https://github.com/ViroCommunity/starter-kit

It has all the config and MainApplication.Java changes already in it. If you can run that, then it will help us work out if there is a problem, or if you have missed a step somewhere.

We also recommend using the stater kit if you are starting a new AR project in any case!

@websasindu
Copy link
Author

Hi Thank you for reply. yes i tried but same error. :/

@bilewinters
Copy link
Contributor

Hi @websasindu in that case I think there is something wrong with your setup, and issues isn't the place to resolve this - come and join our discord, there is a good community who help with these kinds of problems:

https://discord.gg/H3ksm5NhzT

I'm going to close this issue but please join discord and raise it there. If someone there has seen it they may be able to help.

@asadadams
Copy link

@websasindu Did you find the solution to this issue. Also encountering the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants