[安卓]错误:请在 gradle.properties 文件中定义"VERSION_NAME"



最近,我开始学习android开发。我想开发一个具有音频/视频流转换功能的应用程序。所以我尝试导入VLC模块来接收流数据。

当我导入VLC模块时,控制台显示错误。

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

我点击open file。渐变配置文件在IDE中打开。重点是显示'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'

那么,如何编辑渐变配置文件呢?

您需要在defaultConfig:中添加versionName和versionCode

defaultConfig {
versionCode rootProject.ext.versionCode
versionName rootProject.ext.versionName
...

这些可能与应用程序moudle的versionName和versionCode不同。

消息显示gradle.properties,但您打开的是build.gradle脚本。也许该文件还不存在?如果是这样,只需在build.gradle文件旁边创建(或打开(gradle.properties并添加所需的属性。

在插件github页面上,你可以找到更多关于具体内容的信息:

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

相关内容

最新更新