2016-12-14 85 views
0

我正在嘗試在工作android中獲得張量流,有點超出了默認的項目文件夾。我修改了我的build.gradle,但顯然我錯過了一些東西,因爲我的應用程序在運行時崩潰,無法遵守本地庫的不可用性。我花了好幾個小時來解決這個問題,但無濟於事。有人可以幫忙嗎?Android中的Tensorflow,gradle問題

基本上,我比較了通過工作tf demo和我的.so生成的APK中的.so文件,它們是不同的。所以我想我必須在我的腳本的某處...

def bazel_location = '/usr/local/bin/bazel' 
    def tf_location = '/home/poborak/SW/tensorflow-master' 

    def cpuType = 'armeabi-v7a' 
    def nativeDir = 'src/main/jniLibs/' + cpuType 

project.buildDir = 'gradleBuild' 
getProject().setBuildDir('gradleBuild') 

buildscript { 
    System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true' 

    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.3' 
    } 
} 

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 
    defaultConfig { 
     applicationId "bazinac.aplikacenahouby" 
     minSdkVersion 21 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    sourceSets { 
     main { 
      manifest.srcFile 'src/main/AndroidManifest.xml' 
      java.srcDirs = ['src/main/java', tf_location+'/tensorflow/contrib/android/java'] 
      resources.srcDirs = ['src/main/java'] 
      aidl.srcDirs = ['src/main/java'] 
      renderscript.srcDirs = ['src/main/java'] 
      res.srcDirs = ['src/main/res'] 
      assets.srcDirs = ['src/main/assets'] 
      jniLibs.srcDirs = ['src/main/jniLibs'] 
      jni.srcDirs = [] 
     } 

     debug.setRoot('build-types/debug') 
     release.setRoot('build-types/release') 
    } 

    buildTypes { 

     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 

     debug { 
      debuggable true 
     } 
    } 
} 


dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile 'com.android.support:design:23.4.0' 
    testCompile 'junit:junit:4.12' 
    compile 'org.apache.commons:commons-io:1.3.2' 
} 


task buildNative(type:Exec) { 
    workingDir tf_location 
    commandLine bazel_location, 'build', '-c', 'opt', \ 
     'tensorflow/examples/android:tensorflow_native_libs', \ 
     '--crosstool_top=//external:android/crosstool', \ 
     '--cpu=' + cpuType, \ 
     '[email protected]_tools//tools/cpp:toolchain' 
} 

task copyNativeLibs(type: Copy) { 
    from(tf_location+'bazel-bin/tensorflow/examples/android') { include '**/*.so' } 
    into nativeDir 
     duplicatesStrategy = 'include' 
    } 

    copyNativeLibs.dependsOn buildNative 
    assemble.dependsOn copyNativeLibs 

回答

1

最後我找到了解決方法。它將Gradle降級到2.14.xx和Android插件版本2.1.3。然後我添加了assembleDebug.dependsOn copyNativeLibs,它現在可以工作。當然,我還會對更好的解決方案感興趣。 (AssembleDebug屬性在新版APV中無法識別。