[android]ERROR: Please define "VERSION_NAME" in your gradle.properties file

Viewed 166

Recently,i start to learn android development. I want develop an app with audio/video stream transform function.So i tried to import the VLC module to receive the streaming data.

The Console shows error when I import the VLC module.

//the errors console shows
ERROR: Please define "VERSION_NAME" in your gradle.properties file
**Open File**

I click the open file .The gradle configure file opens in IDE.The focus is on the 3rd lines which shows 'apply plugin: "com.vanniktech.maven.publish"'

//gradle configure file
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.vanniktech.maven.publish"

def abi = System.getenv('GRADLE_ABI')?.toLowerCase()
def vlcSrcDirs = System.getenv('GRADLE_VLC_SRC_DIRS')
ext {
    library_version = "$rootProject.ext.libvlcVersion"
}
android {

    defaultConfig {
        compileSdkVersion rootProject.ext.compileSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        minSdkVersion rootProject.ext.minSdkVersion
        resValue "string", "build_vlc_revision", vlcRevision()
        tasks.whenTaskAdded { task ->
            if (task.name.startsWith('merge')) {
                task.dependsOn hrtfsCopy
                task.dependsOn luaPlaylistCopy
                task.dependsOn luaMetaCopy
                task.dependsOn luaModuleCopy
            }
        }

    }

    sourceSets {
        main {
            jni.srcDirs = [] // Prevent gradle from building native code with ndk; we have our own Makefile for it.
            jniLibs.srcDirs = [ 'jni/libs' ]
            jniLibs.srcDirs += "$vlcSrcDirs"
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets' ]
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        dev {
            initWith debug
            matchingFallbacks = ['debug']
        }
    }

    // Make per-variant version code
    libraryVariants.all { variant ->
        //Custom APK name
        variant.outputs.each { output ->
            if (output.outputFileName != null && output.outputFileName.endsWith('.aar')) {
                output.outputFileName = "libvlc-${abi}-${library_version}.aar"
            }
        }
    }

    task hrtfsCopy(type: Copy) {
        project.logger.lifecycle('hrtfsCopy')
        from '../vlc/share/hrtfs'
        into 'assets/hrtfs'
    }

    task luaPlaylistCopy(type: Copy) {
        from '../vlc/share/lua/playlist'
        into 'assets/lua/playlist'
        exclude '**/*.txt'
    }

    task luaModuleCopy(type: Copy) {
        from '../vlc/share/lua/modules'
        into 'assets/lua/modules'
        exclude '**/*.txt'
    }

    task luaMetaCopy(type: Copy) {
        from '../vlc/share/lua/meta'
        into 'assets/lua/meta'
        exclude '**/*.txt'
    }
}

clean {
    delete 'build', 'jni/libs', 'jni/obj'
}

dependencies {

    api "androidx.annotation:annotation:$rootProject.ext.androidxAnnotationVersion"
    api "androidx.legacy:legacy-support-v4:$rootProject.ext.androidxLegacyVersion"
}

def vlcRevision() {
    def vlc = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = vlc
    }
    return vlc.toString()
}

mavenPublish {
    releaseSigningEnabled = false
}

apply from: '../buildsystem/publish.gradle'

So, how can i edit the gradle configure file?

2 Answers

You need to add versionName and versionCode in defaultConfig :

defaultConfig {

        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        ...

these can be different from the versionName and versionCode of your app moudle.

The message says gradle.properties, but what you opened is a build.gradle script. Perhaps the file does not yet exist? If so just create (or open) gradle.properties next to the build.gradle file and add the required property.

on the plugins github page you can find more info on what to put in there exactly:

https://github.com/vanniktech/gradle-maven-publish-plugin

Related