Android Studio 无法找到 Oculus SDK。

3
我刚刚在我的项目中添加了一个库——Gear VRF,但是该库的build.gradle文件无法找到Oculus sdk。我得到了错误信息“未复制Oculus文件:未找到OVR_MOBILE_SDK”,以及“依赖硬编码路径和环境变量;未找到OVR_MOBILE_SDK”。在Gradle日志底部还有“framework:buildNative任务执行失败,User/../../Android/sdk/ndk-bundle/ndk-build以非零退出值2结束”的信息。
对于这个问题的任何帮助都将不胜感激,下面是该库的build.gradle代码,请查看一下,谢谢。
    import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion '23.0.3'

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 19

    ndk {
        moduleName "gvrf"
    }
}

task copyOculusFiles(type: Copy) {
    println "copying oculus binaries"
    if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
        def oculusDir = rootProject.property("OVR_MOBILE_SDK")
        copy {
            from oculusDir+'/VrApi/Libs/Android/VrApi.jar'
            into 'src/main/libs'
        }
        copy {
            from oculusDir+'/VrApi/Libs/Android/armeabi-v7a/libvrapi.so'
            into 'src/main/libs/armeabi-v7a'
        }
        copy {
            from oculusDir+'/VrAppSupport/SystemUtils/Libs/Android/SystemUtils.jar'
            into 'src/main/libs'
        }
    } else {
        println "WARNING: not copying Oculus files; OVR_MOBILE_SDK not found"
    }
}

task buildNative(type: Exec) {
    if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
        environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
    } else {
        println "WARNING: relying on hard-coded paths and environment variables; OVR_MOBILE_SDK not found"
    }

    def ndkbuild = ""
    if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
        ndkbuild = rootProject.property("ANDROID_NDK_HOME")
        ndkbuild += '/'
    }
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkbuild += 'ndk-build.cmd'
    } else {
        ndkbuild += 'ndk-build'
    }

    if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
        environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
    }

    commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16//, 'NDK_DEBUG=1'
}

buildTypes {
    debug {
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
    }
    releaseToGitHub {
    }
}

sourceSets.main {
    java.srcDirs = ['src/main/java', 'src/main/backends/oculus']
    jni.srcDirs = [] // no auto generation of Android.mk
    // pre-compiled libraries
    jniLibs {
        srcDir 'src/main/libs'
    }
}

task cleanNative(type: Exec) {
    def ndkbuild = ""
    if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
        ndkbuild = rootProject.property("ANDROID_NDK_HOME")
        ndkbuild += '/'
    }
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndkbuild += 'ndk-build.cmd'
    } else {
        ndkbuild += 'ndk-build'
    }

    if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
        environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
    }
    commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16, 'clean'
}

clean.dependsOn 'cleanNative'

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn buildNative, copyOculusFiles
}

task eclipseZip(type: Zip) {
    into('GearVRf/res/') {
        from 'src/main/res/'
    }
    into('GearVRf/libs/') {
        from('src/main/libs/') {
            exclude 'libassimp.so'
            exclude 'libjnlua.so'
        }
        from('build/intermediates/bundles/release/') {
            include 'classes.jar'
            rename('classes.jar', 'gvrf.jar')
        }
    }
    into('GearVRf/') {
        from('src/main/') {
            include 'AndroidManifest.xml'
            include '.project'
            include '.classpath'
            include 'project.properties'
        }
    }
    into('GearVRf/java') {
        from('src/main/') {
            include 'donotdelete.txt'
        }
    }

    baseName 'gvrf-for-eclipse'
}

task eclipseAssembleReleaseToGitHub() << {
    println "preparing android library project for eclipse"

    eclipseZip.execute()

    copy {
        from 'build/distributions/gvrf-for-eclipse.zip'
        into 'build/outputs/aar/'
    }

    project.delete('build/distributions/gvrf-for-eclipse.zip')
}

task uploadToGitHub(type: Exec) {
    onlyIf {
        System.env['RELEASE_ID'] != null
    }
    onlyIf {
        System.env['ACCESS_TOKEN'] != null
    }

    commandLine '../../tools/upload_to_github', file('build/outputs/aar/framework-releaseToGitHub.aar').absolutePath
}
uploadToGitHub.doFirst {
    println('uploading to github')
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'src/main/libs', include: ['*.jar'])
}

assembleDebug {}.doLast {
    task copyAARFiles(type: Copy) {
        if (rootProject.hasProperty("LIBS_DIRECTORY")) {
            println "copying aar files to the libs_directory"
            def libsdirPath = projectDir.absolutePath + '/../../../' +
                    rootProject.property("LIBS_DIRECTORY")
            def libsDir = new File(libsdirPath);
            if (libsDir.exists()) {
                from 'build/outputs/aar'
                into libsDir
                include '**/*.aar'
            } else {
                println "Cannot copy aar files, libs directory does not exist!"
            }
        }
    }

assembleReleaseToGitHub {}.doLast {
    println 'removing oculus binaries'
    exec {
        commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/VrApi.jar']
    }
    exec {
        commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/SystemUtils.jar']
    }
    exec {
        commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'jni/armeabi-v7a/libvrapi.so']
    }

    eclipseAssembleReleaseToGitHub.execute()
    uploadToGitHub.execute();
}
1个回答

1

找到gradle.properties文件并添加以下内容:

# Un-comment and add the path to ovr directory
OVR_MOBILE_SDK=\.\.\/GearVRf\/ovr_mobile_sdk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接