Trying to add module to project. Gradle DSL method

2019-08-26 07:57发布

问题:

I am trying to add a epub reader library to a project I have already created. The library I am trying to add to my project as a moduel is the Folio Reader Library (https://github.com/FolioReader/FolioReader-Android). I have downloaded this library on my computer and have tried adding it through File -> New -> Import Module. However, during the process I received countless errors. My current one is this:

Gradle DSL method not found: 'versionName()'
Possible causes:
The project 'FolioReader-Android-master' 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 3.4.1 and sync project

The project 'FolioReader-Android-master' may be using a version of Gradle 
 that does not contain the method.
Open Gradle wrapper file

The build file may be missing a Gradle plugin.
Apply Gradle plugin

This file is the file where the dependencies are declared for the Library.

FolioReader-Android-master:

build.gradle file:

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

buildscript {
apply from: 'versions.gradle'

repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'


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

    //moj
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'



}
}

allprojects {

configurations.all {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
    }
}

repositories {
    mavenLocal()
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
delete rootProject.buildDir
}

The error itself states that the problem arises because the project is using a version of the Gradle plug-in may not contain the method. I have updated the version to the newest one, however I still receive this error. Any suggestions on how I can solve this problem?

回答1:

Problem solved by replacing

versionName 1

with

versionName "1.1"

in the Module level build.gradle file.



回答2:

set it in the build.gradle

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
    applicationId "your package name"
    minSdkVersion 18
    targetSdkVersion 28
    versionCode 1
// this is versionName
        versionName "1.0" 
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }