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

Cannot run app in device emulator #66

Closed
JoeCohen opened this issue Sep 18, 2022 · 25 comments
Closed

Cannot run app in device emulator #66

JoeCohen opened this issue Sep 18, 2022 · 25 comments
Assignees
Labels
Android Android flavor of app emulator iOS iOS flavor of app toolchain Desired toolchain upgrades

Comments

@JoeCohen
Copy link
Member

I'm copying messages from MO's Slack mobile-app channel because those messages are available for only 90 days.

@JoeCohen
Copy link
Member Author

JoeCohen commented Sep 18, 2022

11:57 2022-09-04
@mo-nathan
I'm trying to get the app running in the iOS and Android emulators.
12:03
@mo-nathan
For the iOS, I got the emulator to show up but it doesn't have the app available. The error messages suggested that I need to unlink a couple of libraries. I eventually think I was able to do this with:

yarn react-native unlink react-native-device-info
yarn react-native unlink react-native-image-picker

Not sure that's the right way to do it, but it seems to have gotten me past that hurdle. When I then ran npm run ios-dev it suggested that a rebuild the app with: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace MushroomObserver.xcworkspace -configuration Debug -scheme MushroomObserver -destination id=69BBABFD-6E13-4235-B063-D8401498ED9E
This seemed to do a bunch of work, but then failed with some linker errors. I think the key issue in this case is that I may be using an older version of the iOS Simulator than it is expected which might be related to my trying to get this working on an Apple M1. Specifically I'm seeing issues like this:

ld: warning: object file (/Users/nathan/Library/Developer/Xcode/DerivedData/MushroomObserver-etiaiplacofplddtqfuueaqxvsmf/Build/Products/Debug-iphonesimulator/libPods-MushroomObserver.a(Pods-MushroomObserver-dummy.o)) was built for newer iOS Simulator version (12.0) than being linked (11.0)

and at the end it is saying

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
2022-09-04 14:54:32.361 xcodebuild[38678:1664833] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-09-04 14:54:32.361 xcodebuild[38678:1664833] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
** BUILD FAILED **

The following build commands failed:
	Run custom shell script 'Run Script'
	Ld /Users/nathan/Library/Developer/Xcode/DerivedData/MushroomObserver-etiaiplacofplddtqfuueaqxvsmf/Build/Products/Debug-iphonesimulator/MushroomObserver.app/MushroomObserver normal (in target 'MushroomObserver' from project 'MushroomObserver')
(2 failures)

info Run CLI with --verbose flag for more details.

Not sure how to proceed from here.

@JoeCohen
Copy link
Member Author

@mo-nathan
On the Android front, I'm stuck at:

> Task :app:installDebug FAILED
Installing APK 'app-debug.apk' on 'Pixel_3a_API_33_arm64-v8a(AVD) - 13' for app:debug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
542 actionable tasks: 3 executed, 539 up-to-date
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
Unable to install /Users/nathan/src/mushroom-observer-mobile/android/app/build/outputs/apk/debug/app-debug.apk
com.android.ddmlib.InstallException: Unknown failure: Exception occurred while executing 'install':
android.os.ParcelableException: java.io.IOException: Requested internal only, but not enough space

12:13
Not sure if I need to do something with "Gradle" or if the code needs to be changed or if the real problem is the "not enough space" issue at the end of this chunk.

@JoeCohen
Copy link
Member Author

06:55
@mo-nathan
I was able to get a more reasonable version of the phone working. It's able to run the Chrome app on the simulator and was able to get to mushroomobserver.org. Looks like Joe has gotten to the same place.

06:56
I don't think either of us is able to build the MO app yet and see it, but slow progress is happening.

@JoeCohen
Copy link
Member Author

JoeCohen commented Sep 18, 2022

[9:14 AM] 2022-09-05
@JoeCohen When I try starting the app on the Android emulator (see https://github.com/MushroomObserver/mushroom-observer-mobile#development), I get

joe@Josephs-iMac mushroom-observer-mobile % npm run android-dev

  > mushroomobserver@0.0.1 android-dev
  > ENVFILE=.env.development react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1631 file(s) to forward-jetify. Using 12 workers...
info JS server already running.
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings generic class cache for settings file '/Users/joe/mushroom-observer-mobile/android/settings.gradle' (/Users/joe/.gradle/caches/6.9/scripts/5j9lzav7qxfk1effo982nul64).
BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 62
…

@JoeCohen
Copy link
Member Author

09:23
@JoeCohen On the iOS front, I am in a similar place to
@nathan
; I can get the simulator running, but not the app.
I first received the same error messages about unlinking files,
I fixed that by following the suggestions in error messages:

npx react-native unlink react-native-device-info
npx react-native unlink react-native-image-picker

Then

joe@Josephs-iMac mushroom-observer-mobile % npm run ios-dev

> mushroomobserver@0.0.1 ios-dev
> ENVFILE=.env.development react-native run-ios

info Found Xcode workspace "MushroomObserver.xcworkspace"
info Launching iPhone 13 (iOS 15.2)
info Building (using "xcodebuild -workspace MushroomObserver.xcworkspace -configuration Debug -scheme MushroomObserver -destination id=01C0FC00-65C0-4810-8421-3D4EC9736854")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening MushroomObserver.xcworkspace.
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace MushroomObserver.xcworkspace -configuration Debug -scheme MushroomObserver -destination id=01C0FC00-65C0-4810-8421-3D4EC9736854
...

I did not try to “debug build logs further” because I would not have understood anything. (edited)

@JoeCohen JoeCohen added iOS iOS flavor of app Android Android flavor of app emulator labels Sep 18, 2022
@mo-nathan
Copy link
Member

From email thread on Jan 21, 2024:
Got iOS build working. Feels like a huge milestone! Would love it if someone else on the team wants to see if they can get to the same point. Here's the path I took and the things I learned along the way:

@mo-nathan mo-nathan self-assigned this Feb 12, 2024
@mo-nathan
Copy link
Member

Looked at the Android side of this for a while today. I think the current issue is we need to upgrade Gradle, but it's non-trivial. I don't have a very good understanding of what all that involves.

@mo-nathan
Copy link
Member

Starting from the current main branch of the repo (dc479b1), I have tried the following in Android Studio Hedgehog | 2023.1.1 (Build #AI-231.9392.1.2311.11076708, built on November 9, 2023):

Prep/Reset

% rm -rf node_modules # Not necessary from a fresh pull, but helpful if you're resetting things
% npm install

In Andriod Studio

  • Kick off a build
  • Initially got an error involving the current version of Gradle being out of date with respect to the current version of Java. It recommend upgrading it and provided a link which apparently succeeded. I believe I'm currently on version 7.2 of Gradle (Select File -> Project Structure in Android Studio). The version in the repo is 6.9. I believe the Java version is part of MacOS (Sonoma 14.2.1).
% java --version
openjdk 17.0.9 2023-10-17 LTS
  • The next error I encounter is "Plugin with id 'maven' not found." After a bit of Googling I learned that this plugin should now be loaded with 'maven-publish'. The error should take you to the right place, but the file to update is node_modules/expo-constants/android/build.gradle
  • The next issue was "Cannot resolve symbol 'GradleException'". Apparently this has been replaced with FileNotFoundException, but it seems like this happen a while ago.
  • Build process is not longer reporting errors, but nothing is happening.

@mo-nathan
Copy link
Member

Quit and restarted Android Studio. When I re-entered it kicked off some sort of build that I couldn't get to happen before. It's now reporting: "Gradle DSL method not found: 'uploadArchives()'" and it's recommending that I "Upgrade plugin to version 8.2.0 and sync project".

@mo-nathan
Copy link
Member

Now it's reporting: "Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace."

@mo-nathan
Copy link
Member

Learned about Tools -> AGP Upgrade Assistant in Android Studio. AGP = Android Gradle Plugin. Gradle is the project build tool used by Android Studio. It's like make but whizzier and sadly appears to be a lot less stable thus necessitating an upgrade assistant. It looks like there are at least two ways I could go about upgrading Gradle. What I've been doing is waiting for some build error to generate a recommendation that Gradle be updated and then doing it automatically (which I don't think uses the AGP Upgrade Assistant). Alternatively, I could just run the AGP Upgrade Assistant if I know what the expected destination version is. In my next post I'm going to document what happens when I try these different approaches since neither of them have worked for me yet. At this point I'm wondering if I need to take smaller steps when using the upgrade assistant. However, I need to document stuff first.

@mo-nathan
Copy link
Member

Initialization

  1. Ensure that git status doesn't report any changes. git stash can help make that true.
  2. Run rm -rf node_modeuls; npm install in the mushroom-observer-mobile directory.
  3. Get the iOS version working. Requires adding a | to Yoga.cpp and letting the system create GeneratedDotEnv.m. May also require selecting Product -> Clean Build Folder and running any watchman cleanup commands recommended when Metro starts up.
  4. Shutdown the Apple Simulator and XCode.
  5. Startup Android Studio and load the MushroomObserver project file. It will automatically try to build it and probably hit the error that looks like:
Unsupported Java. 
Your build is currently configured to use Java 17.0.7 and Gradle 6.9.

Possible solution:
 - Upgrade Gradle wrapper to 7.2 version and re-import the project

At this point select File -> Project Structure should indicate that it's using Android Gradle Plugin Version 4.2.2 and Gradle version 6.9.

@mo-nathan
Copy link
Member

Bringing up the Upgrade Assistant, it is recommending version 7.4.2 for the Android Gradle Plugin. By default "Update" is selected which will upgrade Gradle version to 7.5 and upgrade AGP dependency from 4.2.2 to 7.4.2. There are also options for "Recommended post-upgrade steps" which is "Move package from Android manifest to build files", and "Recommended steps" which is "Migrate packagingOptions DSL properties to sub-blocks".

It claims these steps are not required, but I know it will hit a Java conflict if i just try to build things as they are.

Only the "Upgrade" option is selected by default and that's what I tried last time and it seemed to mess stuff up a bit. This time I selected all the options and clicked "Run selected steps". Unfortunately that failed as well with the error:

Calling `[node, /Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/bin.js, config]` finished with an exception. Error message: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'E' with an int value of 69
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Error: Package name not found in /Users/nathan/src/mushroom-observer-mobile/android/app/src/main/AndroidManifest.xml    at Object.projectConfig (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli-platform-android/build/config/index.js:74:11)    at Object.get project [as project] (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/tools/config/index.js:107:50)    at filterConfig (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/commands/config/config.js:13:20)    at Object.func (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/commands/config/config.js:27:32)    at Command.handleAction (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/index.js:192:23)    at Command.listener (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:315:8)    at Command.emit (node:events:513:28)    at Command.parseArgs (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:651:12)    at Command.parse (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:474:21)    at setupAndRun (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/index.js:271:24)info Run CLI with --verbose flag for more details.
^. Output: Error: Package name not found in /Users/nathan/src/mushroom-observer-mobile/android/app/src/main/AndroidManifest.xml    at Object.projectConfig (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli-platform-android/build/config/index.js:74:11)    at Object.get project [as project] (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/tools/config/index.js:107:50)    at filterConfig (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/commands/config/config.js:13:20)    at Object.func (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/commands/config/config.js:27:32)    at Command.handleAction (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/index.js:192:23)    at Command.listener (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:315:8)    at Command.emit (node:events:513:28)    at Command.parseArgs (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:651:12)    at Command.parse (/Users/nathan/src/mushroom-observer-mobile/node_modules/commander/index.js:474:21)    at setupAndRun (/Users/nathan/src/mushroom-observer-mobile/node_modules/@react-native-community/cli/build/index.js:271:24)info Run CLI with --verbose flag for more details.

@mo-nathan
Copy link
Member

Looking at the state of my local git repo after running the above, I see:

% git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   android/app/build.gradle
	modified:   android/app/src/main/AndroidManifest.xml
	modified:   android/build.gradle
	modified:   android/gradle/wrapper/gradle-wrapper.properties

@mo-nathan
Copy link
Member

The most suspicious change in my opinion is:

--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -1,6 +1,5 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    package="org.mushroomobserver.mobile">
+    xmlns:tools="http://schemas.android.com/tools">
 
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

@mo-nathan
Copy link
Member

Found this page which has WAY too many suggestions of what to do next: https://stackoverflow.com/questions/58952564/error-unable-to-determine-the-current-character-it-is-not-a-string-number-ar

@mo-nathan
Copy link
Member

In line with both the above link and the above suspicion, I'm trying:
git checkout android/app/src/main/AndroidManifest.xml

@mo-nathan
Copy link
Member

It's also worth noting that File -> Project Structure now reports Android Gradle Plugin Version = 7.4.2 and Gradle Version = 7.5.

@mo-nathan
Copy link
Member

Also the AGP Upgrade Assistant now wants to upgrade to 8.2.0. I'm going to hold off on that and see where things stand with 7.5.

@mo-nathan
Copy link
Member

mo-nathan commented Feb 15, 2024

Hit the maven issue.

I don't understand how to re-kickoff the Gradle build. Clicking on the little build icon gives me a popup that says "Unable to find Gradle tasks to build []".

Did more poking and saw that it came across the GradleException issue.

Now getting:

8:58:07 PM: Executing...

8:58:07 PM: Execution finished.

Doesn't seem to be doing much.

@mo-nathan
Copy link
Member

After restarting Android Studio, it kicked of Gradle again. Now it's saying:

Gradle DSL method not found: 'uploadArchives()'

Possible causes:

Your project may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).

Upgrade plugin to version 8.2.0 and sync project
Open Gradle wrapper file
Apply Gradle plugin

@mo-nathan
Copy link
Member

@mo-nathan
Copy link
Member

mo-nathan commented Feb 17, 2024

At this point I'm debating what the right strategy is for this work. Options include:

  1. Stick with vanilla Android Studio Hedgehog and try to get the project to build. This strategy seems to be having a confluence of version issues between the version of Java, Gradle, and Node. I'm not seeing a clear next step here.
  2. Try to get the project working with minimal changes. I believe this means making Gradle 6.9 work. This in turn seems to require an earlier version of Java. The one installed with Android Studio Hedgehog is 17.0.7. The first error message I get is "Your build is currently configured to use Java 17.0.9 and Gradle 6.9". I've tried going down the suggested route of upgrading Gradle, but that seems to be stalled. I'm trying to figure out what version of Java is appropriate with Gradle 6.9. At this point I'm guessing it's Java 11. This is largely based on this page https://docs.gradle.org/6.9/release-notes.html which says it only has limited support for Java 16, this page https://docs.gradle.org/6.8/release-notes.html which suggests that it works with Java 11, and this page https://en.wikipedia.org/wiki/Java_version_history which says that the previous long term support version before Java 17 is Java 11.
  3. Go back to iPhone and try to get Node upgraded which might unstick some of the other issues I've encounted with the Android Studio build. This seems like the riskiest approach since I don't see how that helps with the Java/Gradle issue.

@mo-nathan
Copy link
Member

After installing Java 11, I ran into the uploadArchives() issue, but following the recommendations in https://stackoverflow.com/questions/70565069/could-not-find-method-uploadarchives-for-arguments-in-build-gradle I was able to get past this. I think ran into an issue where it was complaining about the version of Kotlin with errors that look like:
"Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1."

I found a setting in Android Studio under Tools -> Kotlin -> Configure Kotlin in Project

However, the oldest version that was available under "Kotlin compiler and runtime version:" was 1.8.20-RC. I tried selecting 1.8.22. It didn't work right away. So I went for a full clean rebuild including selecting 'File -> Invalidate Caches...', quitting Android Studio, deleting node_modules and ~/.gradle then running npm install, reopening Android Studio (where it automatically runs gradle), not clear if things worked after that, but I also ran 'Build -> Clean Project' before things were really working. All of this allowed the build process to complete. However, the emulator wasn't working. I messed around with that including creating a new virtual device and so on. The challenge was that it wasn't connecting to any of the emulators through the drop down at the top of the window. The last thing I did that made that work was selecting "app" from the configurations. It had ~/src/mushroom-observer-mobile/android selected before that. This allowed the icon to show up on the emulator, but it then I had this issue: https://stackoverflow.com/questions/56115077/unable-to-load-script-make-sure-youre-either-running-a-metro-server-run-reac. From what I could tell the Android Studio emulator was not communicating with Metro to build the expected bundle. I followed the instructions in the stackoverflow article, but rather than creating the directory android/app/src/main/{assets} per the instructions I created android/app/src/main/assets. I also ran react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res. I then restarted Metro using npx react-native start. When I went back to Android Studio I was able to get to the login and register screens in the app! Woot! I haven't actually been able to login using the app despite being able to from the Chrome widget in the emulator and being able to login from the iPhone app, but for now I'll take this as "working"!

@mo-nathan
Copy link
Member

mo-nathan commented Feb 24, 2024

I was able to actually login from the Android Studio emulator after updating the .env.development to point to the real MO server with an appropriate API key. I think it's using .env.development because it's building the "debug" variant, but I'm 100% sure of that.

I was able to get the emulator to connect with Metro for dynamic packaging by running: adb reverse tcp:8081 tcp:8081. I was then able to get it to talk to my local MO server by using http://10.0.2.2:3000 in my .env.development (rather than a localhost URL),

@mo-nathan mo-nathan moved this to In Progress in Mobile Task Plan Feb 24, 2024
@mo-nathan mo-nathan added the toolchain Desired toolchain upgrades label Feb 24, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Mobile Task Plan Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android flavor of app emulator iOS iOS flavor of app toolchain Desired toolchain upgrades
Projects
Status: Done
Development

No branches or pull requests

2 participants