tradle / react-native-udp

node's dgram for react-native
MIT License
339 stars 154 forks source link

Compile android error in a clean project #79

Closed tinchoz49 closed 5 years ago

tinchoz49 commented 5 years ago

Hi, first of all, thanks for your work on this library! I used in the past and it worked great.

I'm having a compile error on Android in a clean project.

> Task :react-native-udp:generateDebugBuildConfig UP-TO-DATE
> Task :react-native-udp:prepareLintJar UP-TO-DATE
> Task :react-native-udp:generateDebugSources UP-TO-DATE
> Task :react-native-udp:javaPreCompileDebug UP-TO-DATE
> Task :react-native-udp:compileDebugJavaWithJavac UP-TO-DATE
> Task :react-native-udp:processDebugJavaRes NO-SOURCE
> Task :react-native-udp:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug

> Task :app:compileDebugJavaWithJavac FAILED
/rnproject/android/app/src/main/java/com/rnproject/MainActivity.java:3: error: cannot find symbol
import com.facebook.react.ReactActivity;
                         ^
  symbol:   class ReactActivity
  location: package com.facebook.react
/rnproject/android/app/src/main/java/com/rnproject/MainActivity.java:5: error: cannot find symbol
public class MainActivity extends ReactActivity {
                                  ^
  symbol: class ReactActivity
/rnproject/android/app/src/main/java/com/rnproject/MainApplication.java:5: error: cannot find symbol
import com.facebook.react.ReactApplication;

I know that it seems that error is related to my MainApplication but this only happening if I activate the react-native-udp module.

react-native-cli: 2.0.1 react-native: 0.58.3

How to reproduce it

  1. react-native init newproject
  2. cd newproject
  3. yarn add react-native-udp
  4. react-native link react-native-udp
  5. react-native run-android

MainApplication.java

package com.rnproject;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.tradle.react.UdpSocketsModule;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

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() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new UdpSocketsModule()
      );
    }

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

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

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

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}
hevili commented 5 years ago

same issue here

mvayngrib commented 5 years ago

hey guys, i pushed a fix, can u try it out? install via github for now: npm i -S tradle/react-native-udp

mvayngrib commented 5 years ago

oops, closed by accident

tinchoz49 commented 5 years ago

Hi @mvayngrib !! awesome, it worked. Thanks!! don't forget to publish it.

tinchoz49 commented 5 years ago

I want to ask you about react-native-udp + bittorrent-dht, do you think that it's ok to open a new issue to talk about it?

mvayngrib commented 5 years ago

@tinchoz49 cool, published as 2.4.0

I want to ask you about react-native-udp + bittorrent-dht, do you think that it's ok to open a new issue to talk about it?

sure, open away

tinchoz49 commented 5 years ago

fixed by the release v2.4.0

ejthayer commented 5 years ago

This is not working on my iMac I init a new project, does not matter what method I use to install it, I always get

Task :react-native-udp:compileDebugJavaWithJavac FAILED

It does work on my PC.