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

Create new project or use the repo #49

Closed
Jairolaya12x opened this issue Sep 20, 2019 · 26 comments
Closed

Create new project or use the repo #49

Jairolaya12x opened this issue Sep 20, 2019 · 26 comments
Labels
android This issue is specific to the Android Platform. ar-foundation

Comments

@Jairolaya12x
Copy link

I follow all the steps for create my project and setup this, but when need add as library the .jar i don't have the same flow, and don't works the question is: Is necessary use the repo for create the unity plugin or should work with a new project create by me. because for example if open in android studio see different the project first variation

My project, (The icon under Project is a folder and the android folder have [name_android])
image

The repo (The icon under Project is flutter icon)
image

Add as library:

This is my project but don't show all the settings.
image

This is the window of the repo when try to add as library
image

Hope that anyone can help me with this please,

Thanks!

@TarekMedhat
Copy link

Hi @Jairolaya12x , You don't have to use the repo example project, you can create your own project.

Steps: 1- Add your unity project to "unity" folder
2- Export to Android, if succeeded a project named UnityExport will be added to the "android" folder
3- To add the jar library open the "android" project in a separate android studio window
4- File > New > New Module > Import .JAR/AAR Package > Select android/UnityExport/libs/unity-classes.jar, (That should create a folder android/unity-classes for you, if there is already a folder with that name delete it first so you can do this step)
5- Make sure that include ':unity-classes' and

include ":UnityExport"
project(":UnityExport").projectDir = file("./UnityExport")

are added to your settings.gradle file
settingsgradle

6- If using Unity 2019.2 or older, open build.gradle of UnityExport module and remove these

bundle {
     language {
         enableSplit = false
     }
     density {
         enableSplit = false
     }
     abi {
         enableSplit = true
     }
 }

7- That's it, go back to your flutter project and run

@Jairolaya12x
Copy link
Author

Great thanks i'll test and let you know, quick question what is the reason of the different icon?
And try using AR but don't works, maybe you have a reference? because i follow steps that the guide and don't works but suppose that making the modules like u say should works

@juicycleff
Copy link
Owner

@Jairolaya12x if you encounter any issues, please mention it here, The examples need to be updated too. As the library has moved a bit fare from it

@Jairolaya12x
Copy link
Author

I don't found any issue yet, but the importation of libs how say @TarekMedhat works fine, the icon change and works like the guide in the tutorial, maybe add this solution in new tutorial for help other people, i'll make more test with AR and post any issue or problem Thanks!

@MichealReed
Copy link

I am trying to work with Unity's AR samples repository, but cannot seem to get the libraries linked up. Following @TarekMedhat 's method above, I added the unity_classes.jar and *.arr files to the UnityExport project, but still see this error:

   > Could not find :arcore_client:.
     Required by:
         project :flutter_unity_widget > project :UnityExport
   > Could not find :ARPresto:.
     Required by:
         project :flutter_unity_widget > project :UnityExport
   > Could not find :unityandroidpermissions:.
     Required by:
         project :flutter_unity_widget > project :UnityExport
   > Could not find :UnityARCore:.
     Required by:
         project :flutter_unity_widget > project :UnityExport

@thomas-stockx
Copy link
Collaborator

@MichealReed Have you followed the steps described here?

https://github.com/snowballdigital/flutter-unity-view-widget#ar-foundation-not-compatible-with-unity-20193

You'll need to create other modules for all AR dependencies (similar to how you added the unity_classes.jar).

@MichealReed
Copy link

MichealReed commented Oct 8, 2019 via email

@thomas-stockx
Copy link
Collaborator

@MichealReed

Have you setup your modules like this?

Screen Shot 2019-10-17 at 1 57 37 PM

You'll need to create a module for every .aar dependency that was in the UnityExport/libs folder, and be sure to add them to settings.gradle like so:

include ':app', ':unity-classes', ':arcore-client', ':unityandroidpermissions'

@thomas-stockx thomas-stockx added android This issue is specific to the Android Platform. ar-foundation labels Oct 17, 2019
@MichealReed
Copy link

MichealReed commented Oct 17, 2019

@thomas-stockx should include ':app', ':unity-classes', ':arcore-client', ':unityandroidpermissions' be in both the android project and UnityExport settings.gradle? In your screenshot, it seems the libraries were added to the android project.

If I remove the includes from the settings.gradle inside the UnityExport folder, it compiles, but the app posts a blank screen even with camera permissions givens.

@thomas-stockx
Copy link
Collaborator

@MichealReed Yes, they should be in the Android project, as we'll compile the whole project and not just the UnityExport module.

Do you seen any errors in logcat which could explain the blank screen?

@leemuljadi
Copy link

Hi @Jairolaya12x ,

I have tried following the instruction from @TarekMedhat, but the game still didn't show up in my own project app.
But I realise that I don't have the .setting folders and .project folder marked in red as below:
image

Does something has to do with it?

Thanks!

@thomas-stockx
Copy link
Collaborator

Hi @leemuljadi,

Those hidden folders are unrelated. Can you please state the compile or build error you're having?

@leemuljadi
Copy link

leemuljadi commented Jan 8, 2020

Hi @thomas-stockx,

Thanks for the reply.
It can compile with no error message, but the problem is, I use a button to call the UnityWidget class but the game doesn't show up when the button is pressed.

Code for the UnityWIdget Class:

import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

class ShooterGame extends StatefulWidget {
  @override
  _ShooterGameState createState() => _ShooterGameState();
}

class _ShooterGameState extends State<ShooterGame> {
  static final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>();
  UnityWidgetController _unityWidgetController;
  double _sliderValue = 0.0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
//        appBar: AppBar(
//          title: const Text('Unity Flutter Demo'),
//        ),
      body: Card(
        margin: const EdgeInsets.all(8),
        clipBehavior: Clip.antiAlias,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20.0),
        ),
        child: Stack(
          children: <Widget>[
            UnityWidget(
              onUnityViewCreated: onUnityCreated,
              isARScene: false,
              onUnityMessage: onUnityMessage,
            ),
//              Positioned(
//                bottom: 20,
//                left: 20,
//                right: 20,
//                child: Card(
//                  elevation: 10,
//                  child: Column(
//                    children: <Widget>[
//                      Padding(
//                        padding: const EdgeInsets.only(top: 20),
//                        child: Text("Rotation speed:"),
//                      ),
//                      Slider(
//                        onChanged: (value) {
//                          setState(() {
//                            _sliderValue = value;
//                          });
//                          setRotationSpeed(value.toString());
//                        },
//                        value: _sliderValue,
//                        min: 0,
//                        max: 20,
//                      ),
//                    ],
//                  ),
//                ),
//              ),
          ],
        ),
      ),
    );
  }

//  void setRotationSpeed(String speed) {
//    _unityWidgetController.postMessage(
//      'Cube',
//      'SetRotationSpeed',
//      speed,
//    );
//  }

  void onUnityMessage(controller, message) {
    print('Received message from unity: ${message.toString()}');
  }

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;
  }
}

@thomas-stockx
Copy link
Collaborator

Any logs to help me figure out what's going wrong?

Are you embedding your ShooterGame widget into another widget, or are you pushing a route to the ShooterGame widget? Do you see the widget in the layout inspector and/or does it have a width/height of 0?

This looks more like an implementation issue than a bug in the library.

@leemuljadi
Copy link

Hi @thomas-stockx,

Unfortunately there no log showing, even when I run in verbose.

Basically I just put the ShooterGame widget inside of the onPressed function of a MaterialButton as code below:

 return SafeArea(
      child: Scaffold(
        body: Center(
          child: MaterialButton(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(AppScreen.s25)),
              onPressed: () => ShooterGame(),
              color: AppColor.secondary,
              child: Text('PLAY GAMES', style: AppTextStyle.boldWhite)),
        ),
      ),
    );

Does it has something to do with these?
image
image
image

@thomas-stockx
Copy link
Collaborator

Hi @leemuljadi,

onPressed: () => ShooterGame(), is not how you would instantiate a widget in your widget tree.

Either you use a state with a visibility boolean which you change with setState in your onPressed, or you push a new route to the ShooterGame widget.

You can find the documentation of pushing a new route here:
https://flutter.dev/docs/cookbook/navigation/navigation-basics

@leemuljadi
Copy link

Hi @thomas-stockx,

It does work now!!!
Thanks so much for your help!

But I got another problem that the app suddenly closed when exit the game.
I tried using navigator.push and navigator.pushreplacement, but it still produce the same error.

Error log:

E/flutter (19771): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (19771): At this point the state of the widget's element tree is no longer stable.
E/flutter (19771): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter (19771): #0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3508:9)
E/flutter (19771): #1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3522:6)
E/flutter (19771): #2      Element.visitAncestorElements (package:flutter/src/widgets/framework.dart:3716:12)
E/flutter (19771): #3      Notification.dispatch (package:flutter/src/widgets/notification_listener.dart:61:13)
E/flutter (19771): #4      ScrollActivity.dispatchScrollEndNotification (package:flutter/src/widgets/scroll_activity.dart:106:63)
E/flutter (19771): #5      ScrollPosition.didEndScroll (package:flutter/src/widgets/scroll_position.dart:724:14)
E/flutter (19771): #6      ScrollPosition.beginActivity (package:flutter/src/widgets/scroll_position.dart:693:9)
E/flutter (19771): #7      ScrollPositionWithSingleContext.beginActivity (package:flutter/src/widgets/scroll_position_with_single_context.dart:116:11)
E/flutter (19771): #8      ScrollPositionWithSingleContext.goIdle (package:flutter/src/widgets/scroll_position_with_single_context.dart:131:5)
E/flutter (19771): #9      ScrollPositionWithSingleContext.goBallistic (package:flutter/src/widgets/scroll_position_with_single_context.dart:150:7)
E/flutter (19771): #10     DrivenScrollActivity._end (package:flutter/src/widgets/scroll_activity.dart:634:15)
E/flutter (19771): #11     _rootRun (dart:async/zone.dart:1122:38)
E/flutter (19771): #12     _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (19771): #13     _FutureListener.handleWhenComplete (dart:async/future_impl.dart:163:18)
E/flutter (19771): #14     Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:650:39)
E/flutter (19771): #15     Future._propagateToListeners (dart:async/future_impl.dart:706:37)
E/flutter (19771): #16     Future._completeWithValue (dart:async/future_impl.dart:524:5)
E/flutter (19771): #17     Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
E/flutter (19771): #18     _rootRun (dart:async/zone.dart:1126:13)
E/flutter (19771): #19     _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (19771): #20     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (19771): #21     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (19771): #22     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (19771): #23     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)

@thomas-stockx
Copy link
Collaborator

Hi @leemuljadi,

Sadly that's an issue with the current Android implementation of Unity as a Library, you can track that issue here: #46.

@leemuljadi
Copy link

Alright thanks so much @thomas-stockx.
Hopefully that this Android issue can be resolved soon :)

@Jairolaya12x
Copy link
Author

Hi @thomas-stockx I created all the modules for AR Foundation in iOS works fine but in android get the same error that @MichealReed

Could not find :arcore_client:.
Required by:
project :flutter_unity_widget > project :UnityExport
Could not find :ARPresto:.
Required by:
project :flutter_unity_widget > project :UnityExport
Could not find :unityandroidpermissions:.
Required by:
project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :flutter_unity_widget > project :UnityExport

Any idea about this?

Thanks!

@GokulDas027
Copy link

This issue have better instruction than at the readme, consider adding some more details to the readme.
I had plans to help with that, but I still haven't fixed setting up my project..😅😅

@GokulDas027
Copy link

GokulDas027 commented Feb 1, 2020

I don't have a settings.gradle file inside the UnityExport..

and having error

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ':app:preDebugBuild'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not find :arcore_client:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :unityandroidpermissions:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

EDIT: It's solved after I replaced the unity-classes.jar file in the unity-classes folder with a copy of unity-classes.jar file from UnityExport

might be some misunderstandings, it came back.. the error is still there

@bahadryalcn
Copy link

I don't have a settings.gradle file inside the UnityExport..

and having error

FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ':app:preDebugBuild'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not find :arcore_client:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :unityandroidpermissions:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

EDIT: It's solved after I replaced the unity-classes.jar file in the unity-classes folder with a copy of unity-classes.jar file from UnityExport

might be some misunderstandings, it came back.. the error is still there

Is there any update on your project ? I am also getting this error.
image

I believe I could not import these jar and aar files as a module. I saw screenshot of @thomas-stockx . When i tried to import these files as a module I am also getting this error.

image

I will be waiting for your answer guys .

@Soorya611
Copy link

I don't have a settings.gradle file inside the UnityExport..
and having error
FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ':app:preDebugBuild'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not find :arcore_client:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :unityandroidpermissions:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

EDIT: It's solved after I replaced the unity-classes.jar file in the unity-classes folder with a copy of unity-classes.jar file from UnityExport
might be some misunderstandings, it came back.. the error is still there

Is there any update on your project ? I am also getting this error.
image

I believe I could not import these jar and aar files as a module. I saw screenshot of @thomas-stockx . When i tried to import these files as a module I am also getting this error.

image

I will be waiting for your answer guys .

facing same issue. did you found any solution?

@tm8981
Copy link

tm8981 commented Aug 19, 2020

I don't have a settings.gradle file inside the UnityExport..
and having error
FAILURE: Build failed with an exception.

  • What went wrong:
    Could not determine the dependencies of task ':app:preDebugBuild'.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not find :arcore_client:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :unityandroidpermissions:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

EDIT: It's solved after I replaced the unity-classes.jar file in the unity-classes folder with a copy of unity-classes.jar file from UnityExport
might be some misunderstandings, it came back.. the error is still there

Is there any update on your project ? I am also getting this error.
image
I believe I could not import these jar and aar files as a module. I saw screenshot of @thomas-stockx . When i tried to import these files as a module I am also getting this error.
image
I will be waiting for your answer guys .

facing same issue. did you found any solution?

  • Try updating the dependencies in unityExport's build.gradle to :

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/arcore_client.aar')
compile files('libs/unityandroidpermissions.aar')
compile files('libs/UnityARCore.aar')
}

@Jatin-Pawar
Copy link

Simply follow the following steps:

  1. Open the "android" folder as a project in Android Studio.
  2. Now, try to import .aar files by File > New > New Module > Import .JAR/AAR Package > Select android/UnityExport/libs/arcore-client.aar (This should import the files without any error.)
  3. After step 2, you can check your UnityExport/settings.gradle file to find out that include ':arcore_client'` has been added at the top. (If not kindly add it.)
  4. Repeat the above 2 steps for all the .arr/.jar files in the UnityExport/libs folder.

This way you will be able to add all the .aar/.jar files and hence should not receive the below error.

Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
Could not find :arcore_client:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

Could not find :unityandroidpermissions:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport
Could not find :UnityARCore:.
Required by:
project :app > project :flutter_unity_widget > project :UnityExport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android This issue is specific to the Android Platform. ar-foundation
Projects
None yet
Development

No branches or pull requests