frostney / react-native-create-library

:notebook: Command line tool to create a React Native library with a single command
MIT License
1.45k stars 113 forks source link

UnknownPluginException: Plugin with id 'com.android.library' not found #12

Closed npomfret closed 7 years ago

npomfret commented 8 years ago

The default android project doesn't seem to work for me. I get the errors:

INFO - .project.GradleProjectResolver - Gradle project resolve error 
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.10-all.zip'.
...
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'blah/MyFancyLibrary/android/build.gradle' line: 2
A problem occurred evaluating root project 'android'.
...
Caused by: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'android'.
...
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'com.android.library' not found.

What am I doing wrong?

frostney commented 8 years ago

Hi @npomfret and thank you for using this tool. Would you mind checking if you installed the "Android Support Repository" in your Android SDK manager?

npomfret commented 8 years ago

Yes, Android Support Repository is installed (version 35.0.0)

npomfret commented 8 years ago

Any update on this? Has anyone managed the get the generated android project to work in android studio? How do you use it if not?

npomfret commented 8 years ago

After much hacking around with the generated gradle file, I ended up with the following that seems to make android studio happy. The trick seems to be to tell gradle about jcenter, twice. Oh, and to tell gradle about gradle...

//this bit is new
build script {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        idk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    lintOptions {
       warning 'InvalidPackage'
    }
}

//this bit is new
all projects {
    repositories {
        jcenter()
    }
}

dependencies {
    compile 'com.facebook.react:react-native:0.20.+'
}

I didn't want to submit it as a PR (yet) as I have no idea what the changes I've made actually mean. Gradle is a total mystery to me and I wouldn't want even to suggest this going in without some discussion.

npomfret commented 8 years ago

Has anyone managed to get the java project working in Android studio without making these modifications to the generated gradle file?

vikeri commented 7 years ago

I got the same error but couldn't get it to work with your gradle file either 😞

vikeri commented 7 years ago

What I got working was the following:


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    lintOptions {
       warning 'InvalidPackage'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.facebook.react:react-native:+'
}
npomfret commented 7 years ago

I've asked about setting up android build files that don't compile on a few other repos. It seems to me (in general) that a lot of react-native people just don't care about compiling java code in isolation of a project. People commonly build RN native libraries that just don't compile unless you embed them in another project... which seems like madness to me. In some RN library projects, most (maybe 99%) of the code has nothing to do with RN, its just pure java. And it should be compilable and testable in isolation in my opinion. But I don't know how to convince others of this. This project is a good example. I think everything in here would work IF you embedded the library you create into a fully functional RN project.

vikeri commented 7 years ago

Yeah I had that exact issue, I do depend on com.facebook.react packages, but from what I saw the latest version on Maven is 0.20 and I used APIs that were newer than that. So I had to compile my project with an RN app in order to get the latest com.facebook.react jar from node_modules/react-native.

frostney commented 7 years ago

I just released version 3.0.0 which includes these fixes to the build.gradle file. Thank you for reporting the issue and investigating this 👍

Krammig commented 6 years ago

@npomfret For what its worth, Gradle is a mystery to the whole world !! The amount of time this thing consumes if trying to debug is absolutely ridiculous. I have had problem after problem with a fairly large project. Fix one thing and something else complains. The incompatibilities between Gradle and Studio and other, the deprications, it's just crazy. Yep you're right, I am not happy :)

By the way @npomfret and @vikeri thanks for the suggestions, didn't work for me unfortunately so I will keep running in circles.

gsunsnackv commented 5 years ago

@npomfret For what its worth, Gradle is a mystery to the whole world !! The amount of time this thing consumes if trying to debug is absolutely ridiculous. I have had problem after problem with a fairly large project. Fix one thing and something else complains. The incompatibilities between Gradle and Studio and other, the deprications, it's just crazy. Yep you're right, I am not happy :)

By the way @npomfret and @vikeri thanks for the suggestions, didn't work for me unfortunately so I will keep running in circles.

I totally agree that gradle is piece of shit and should be erased from this world.