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

Java project error: cannot find symbol: OpenSourceMergedSoMapping #47633

Closed
ObscurusGrassator opened this issue Nov 15, 2024 · 9 comments
Closed
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.

Comments

@ObscurusGrassator
Copy link

Description

I create new r.n. app (by last instruction) and transform kotlin files to java (Kotlin files working good).
(By the way, it is a huge fail that you have officially stopped supporting Java projects)

Steps to reproduce

I create new r.n. app (by last instruction) and transform kotlin files to java (Kotlin files working good).
(By the way, it is a huge fail that you have officially stopped supporting Java projects)

There is probably a problem with overwriting this file:
MainApplication.java:

package com.aaatest;

import android.app.Application;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactHost;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.react.defaults.DefaultReactHost;
import com.facebook.react.soloader.OpenSourceMergedSoMapping;
import com.facebook.soloader.SoLoader;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  @Override
  public ReactNativeHost getReactNativeHost() {
    return new DefaultReactNativeHost(this) {
      @Override
      public boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
      }

      @Override
      protected List<ReactPackage> getPackages() {
        @SuppressWarnings("UnnecessaryLocalVariable")
        List<ReactPackage> packages = new PackageList(this).getPackages();
        return packages;
      }

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

      @Override
      protected boolean isNewArchEnabled() {
        return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
      }

      @Override
      protected Boolean isHermesEnabled() {
        return BuildConfig.IS_HERMES_ENABLED;
      }
    };
  }

  @Override
  public ReactHost getReactHost() {
    return DefaultReactHost.getDefaultReactHost(getApplicationContext(), getReactNativeHost());
  }
      
  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, OpenSourceMergedSoMapping);

    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      DefaultNewArchitectureEntryPoint.load();
    }
  }
}

React Native Version

0.76.2

Affected Platforms

Runtime - Android, Build - MacOS

Output of npx react-native info

<details>
<summary>npx react-native info:</summary>
System:
  OS: macOS 14.7
  CPU: (12) arm64 Apple M2 Max
  Memory: 509.55 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.17.0
    path: ~/.nvm/versions/node/v20.17.0/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v20.17.0/bin/npm
  Watchman:
    version: 2024.04.08.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | AOSP ATD ARM 64 v8a
      - android-34 | ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | AOSP ATD ARM 64
      - android-35 | ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-35 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
      - android-35 | Pre-Release 16 KB Page Size Google APIs ARM 64 v8a
      - android-35 | Google APIs ATD ARM 64
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.6
    path: /usr/bin/javac
  Ruby:
    version: 2.7.8
    path: /opt/homebrew/opt/[email protected]/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.2
    wanted: 15.1.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.2
    wanted: 0.76.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
<details>

Stacktrace or Logs

MainApplication.java:64: error: cannot find symbol
    SoLoader.init(this, OpenSourceMergedSoMapping);
                        ^
  symbol:   variable OpenSourceMergedSoMapping
  location: class MainApplication
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Interesting: the import does not report a problem:

import com.facebook.react.soloader.OpenSourceMergedSoMapping;


### Reproducer

 a

### Screenshots and Videos

_No response_
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Nov 15, 2024
@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@shubhamguptadream11
Copy link
Collaborator

@ObscurusGrassator Can you re-try after cleaning all the caches ones?

  • node_modules
  • gradle cache
  • android build folder

@ObscurusGrassator
Copy link
Author

@shubhamguptadream11 No, cleaning all the caches did not help.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Nov 18, 2024
@root-io
Copy link

root-io commented Nov 19, 2024

Same issue following https://react-native-community.github.io/upgrade-helper/?from=0.75.4&to=0.76.2 and still having a MainApplication.java instead of kt. I also cleaned everything.

@ruijiang
Copy link

Same here. Followed https://reactnative.dev/blog/2024/10/23/release-0.76-new-architecture#breaking-changes-1 to upgrade to 0.76.2, and hit this too!

@limal
Copy link

limal commented Nov 21, 2024

Same here.

If you're facing the problem it's worth converting just your MainApplication.java to MainApplication.kt. It's quite easy to do actually.

The rest of your files, including MainActivity.java and your custom native modules, can stay in Java.

  1. Rename and transform your MainApplication.java file to MainApplication.kt using React Native Upgrade Helper reference or an LLM.
  2. Add apply plugin: "org.jetbrains.kotlin.android"line at the top of app/build.gradle.
  3. Add below 2 lines in your build.gradle.
buildscript {
    ext {
        /* ... */
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.22".   <------ ADD THIS
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        /* ... */
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'. <------ ADD THIS
        ``` 

@Hyeeeein
Copy link

저도 마찬가지예요.

문제에 직면했다면 그냥 당신 MainApplication.java으로 변환하는 게 가치가 있습니다 MainApplication.kt. 실제로 하는 건 꽤 쉽습니다.

MainActivity.java사용자 정의 네이티브 모듈을 비롯한 나머지 파일은 Java로 유지해도 됩니다.

  1. React Native Upgrade Helper 참조나 LLM을 사용하여 MainApplication.java파일의 이름을 바꾸고 변환합니다 .MainApplication.kt
  2. apply plugin: "org.jetbrains.kotlin.android"맨 위에 줄을 추가합니다 app/build.gradle.
  3. 아래 두 줄을 추가하세요 build.gradle.
buildscript {
    ext {
        /* ... */
        ndkVersion = "26.1.10909125"
        kotlinVersion = "1.9.22".   <------ ADD THIS
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        /* ... */
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0'. <------ ADD THIS
        ``` 

It worked successfully! Thank you. However, I'm really curious as to why Java couldn't find the symbol.

@c100k
Copy link

c100k commented Nov 26, 2024

In MainApplication.java, use SoLoader.init(this, OpenSourceMergedSoMapping.INSTANCE);.

Don't forget to catch the IOException that can occur.

@ObscurusGrassator
Copy link
Author

Thanks @c100k , your solution doesn't throw an error, so I can close this issue.
Unfortunately, I cannot test my app, as the new react native architecture has a problem with custom C++ script builds ( #47904 ).
I asked the author of the article ( https://ankitmaheshwariin.medium.com/convert-react-native-android-codebase-from-kotlin-to-java-3f1bc331e963 ) for an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.
Projects
None yet
Development

No branches or pull requests

8 participants