Android Studio无法找到Oculus SDK

时间:2016-08-10 14:46:22

标签: android android-studio sdk oculus

我刚刚在我的项目Gear VRF中添加了一个库,并且该库的build.gradle文件无法找到Oculus sdk。我收到错误"没有复制Oculus文件:找不到OVR_MOBILE_SDK,以及"依赖于硬编码路径和环境变量;找不到OVR_MOBILE_SDK。在Gradle日志的底部,我还得到了任务框架执行失败:buildNative。用户/../../ 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 个答案:

答案 0 :(得分:1)

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

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