2016-12-06 6 views
0

Мне удалось успешно запустить проект в Eclipse. Но когда я пытаюсь обновить свой проект до студии Android, он перестает работать на меня. Я пробовал все, но он не работает. Ниже приведен мой код файла build.gradle.Не удалось запустить уже скомпилированный .so файл в проекте студии Android.

apply plugin: 'android' 
 

 
buildscript { 
 
    repositories { 
 
     mavenCentral() 
 
    } 
 

 
    // Switch the Android Gradle plugin version requirement depending on the 
 
    // installed version of Gradle. This dependency is documented at 
 
    // http://tools.android.com/tech-docs/new-build-system/version-compatibility 
 
    // and https://issues.apache.org/jira/browse/CB-8143 
 
    dependencies { 
 
     classpath 'com.android.tools.build:gradle:2.2.2' 
 
    } 
 
} 
 

 
// Allow plugins to declare Maven dependencies via build-extras.gradle. 
 
repositories { 
 
    mavenCentral() 
 
} 
 

 
task wrapper(type: Wrapper) { 
 
    gradleVersion = '2.2.1' 
 
} 
 

 
// Configuration properties. Set these via environment variables, build-extras.gradle, or gradle.properties. 
 
// Refer to: http://www.gradle.org/docs/current/userguide/tutorial_this_and_that.html 
 
ext { 
 
    apply from: 'CordovaLib/cordova.gradle' 
 
    // The value for android.compileSdkVersion. 
 
    if (!project.hasProperty('cdvCompileSdkVersion')) { 
 
     cdvCompileSdkVersion = privateHelpers.getProjectTarget() 
 
    } 
 
    // The value for android.buildToolsVersion. 
 
    if (!project.hasProperty('cdvBuildToolsVersion')) { 
 
     cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools() 
 
    } 
 
    // Sets the versionCode to the given value. 
 
    if (!project.hasProperty('cdvVersionCode')) { 
 
     cdvVersionCode = null 
 
    } 
 
    // Sets the minSdkVersion to the given value. 
 
    if (!project.hasProperty('cdvMinSdkVersion')) { 
 
     cdvMinSdkVersion = null 
 
    } 
 
    // Whether to build architecture-specific APKs. 
 
    if (!project.hasProperty('cdvBuildMultipleApks')) { 
 
     cdvBuildMultipleApks = false 
 
    } 
 
    // .properties files to use for release signing. 
 
    if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) { 
 
     cdvReleaseSigningPropertiesFile = null 
 
    } 
 
    // .properties files to use for debug signing. 
 
    if (!project.hasProperty('cdvDebugSigningPropertiesFile')) { 
 
     cdvDebugSigningPropertiesFile = null 
 
    } 
 
    // Set by build.js script. 
 
    if (!project.hasProperty('cdvBuildArch')) { 
 
     cdvBuildArch = null 
 
    } 
 
} 
 

 
def hasBuildExtras = file('build-extras.gradle').exists() 
 
if (hasBuildExtras) { 
 
    apply from: 'build-extras.gradle' 
 
} 
 

 
def computeBuildTargetName(debugBuild) { 
 
    def ret = 'assemble' 
 
    if (cdvBuildMultipleApks && cdvBuildArch) { 
 
     def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch 
 
     ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1); 
 
    } 
 
    return ret + (debugBuild ? 'Debug' : 'Release') 
 
} 
 

 
// Make cdvBuild a task that depends on the debug/arch-sepecific task. 
 
task cdvBuildDebug 
 
cdvBuildDebug.dependsOn { 
 
    return computeBuildTargetName(true) 
 
} 
 

 
task cdvBuildRelease 
 
cdvBuildRelease.dependsOn { 
 
    return computeBuildTargetName(false) 
 
} 
 

 
task cdvPrintProps << { 
 
    println('cdvCompileSdkVersion=' + cdvCompileSdkVersion) 
 
    println('cdvBuildToolsVersion=' + cdvBuildToolsVersion) 
 
    println('cdvVersionCode=' + cdvVersionCode) 
 
    println('cdvMinSdkVersion=' + cdvMinSdkVersion) 
 
    println('cdvBuildMultipleApks=' + cdvBuildMultipleApks) 
 
    println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile) 
 
    println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile) 
 
    println('cdvBuildArch=' + cdvBuildArch) 
 
    println('computedVersionCode=' + android.defaultConfig.versionCode) 
 
    if (android.productFlavors.has('armv7')) { 
 
     println('computedArmv7VersionCode=' + android.productFlavors.armv7.versionCode) 
 
    } 
 
    if (android.productFlavors.has('x86')) { 
 
     println('computedx86VersionCode=' + android.productFlavors.x86.versionCode) 
 
    } 
 
} 
 

 
// PLUGIN GRADLE EXTENSIONS START 
 
// PLUGIN GRADLE EXTENSIONS END 
 

 
android { 
 
    sourceSets { 
 
     main { 
 
      manifest.srcFile 'AndroidManifest.xml' 
 
      java.srcDirs = ['src'] 
 
      resources.srcDirs = ['src'] 
 
      aidl.srcDirs = ['src'] 
 
      renderscript.srcDirs = ['src'] 
 
      res.srcDirs = ['res'] 
 
      assets.srcDirs = ['assets'] 
 
     } 
 
    } 
 

 
    def versionCodeOverride = cdvVersionCode ? Integer.parseInt(cdvVersionCode) : null 
 
    def minSdkVersionOverride = cdvMinSdkVersion ? Integer.parseInt(cdvMinSdkVersion) : null 
 

 
    defaultConfig { 
 
     versionCode versionCodeOverride ?: Integer.parseInt("" + privateHelpers.extractIntFromManifest("versionCode") + "0") 
 
     if (minSdkVersionOverride != null) { 
 
      minSdkVersion minSdkVersionOverride 
 
     } 
 
    } 
 

 
    compileSdkVersion cdvCompileSdkVersion 
 
    buildToolsVersion cdvBuildToolsVersion 
 

 
    if (Boolean.valueOf(cdvBuildMultipleApks)) { 
 
     productFlavors { 
 
      armv7 { 
 
       versionCode versionCodeOverride ?: defaultConfig.versionCode + 2 
 
       ndk { 
 
        abiFilters "armeabi-v7a", "" 
 
       } 
 
      } 
 
      x86 { 
 
       versionCode versionCodeOverride ?: defaultConfig.versionCode + 4 
 
       ndk { 
 
        abiFilters "x86", "" 
 
       } 
 
      } 
 
      all { 
 
       ndk { 
 
        abiFilters "all", "" 
 
       } 
 
      } 
 
     } 
 
    } else if (!versionCodeOverride) { 
 
     def minSdkVersion = minSdkVersionOverride ?: privateHelpers.extractIntFromManifest("minSdkVersion") 
 
     // Vary versionCode by the two most common API levels: 
 
     // 14 is ICS, which is the lowest API level for many apps. 
 
     // 20 is Lollipop, which is the lowest API level for the updatable system webview. 
 
     if (minSdkVersion >= 20) { 
 
     defaultConfig.versionCode += 9 
 
     } else if (minSdkVersion >= 14) { 
 
     defaultConfig.versionCode += 8 
 
     } 
 
    } 
 

 
    compileOptions { 
 
     sourceCompatibility JavaVersion.VERSION_1_6 
 
     targetCompatibility JavaVersion.VERSION_1_6 
 
    } 
 

 
    if (cdvReleaseSigningPropertiesFile) { 
 
     signingConfigs { 
 
      release { 
 
       // These must be set or Gradle will complain (even if they are overridden). 
 
       keyAlias = "" 
 
       keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph. 
 
       storeFile = null 
 
       storePassword = "__unset" 
 
      } 
 
     } 
 
     buildTypes { 
 
      release { 
 
       signingConfig signingConfigs.release 
 
      } 
 
     } 
 
     addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release) 
 
    } 
 
    if (cdvDebugSigningPropertiesFile) { 
 
     addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug) 
 
    } 
 
} 
 

 
dependencies { 
 
    compile fileTree(dir: 'libs', include: '*.jar') 
 
    // SUB-PROJECT DEPENDENCIES START 
 
    // SUB-PROJECT DEPENDENCIES END 
 
} 
 

 
def promptForReleaseKeyPassword() { 
 
    if (!cdvReleaseSigningPropertiesFile) { 
 
     return; 
 
    } 
 
    if ('__unset'.equals(android.signingConfigs.release.storePassword)) { 
 
     android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ') 
 
    } 
 
    if ('__unset'.equals(android.signingConfigs.release.keyPassword)) { 
 
     android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: '); 
 
    } 
 
} 
 

 
gradle.taskGraph.whenReady { taskGraph -> 
 
    taskGraph.getAllTasks().each() { task -> 
 
     if (task.name == 'validateReleaseSigning') { 
 
      promptForReleaseKeyPassword() 
 
     } 
 
    } 
 
} 
 

 
def addSigningProps(propsFilePath, signingConfig) { 
 
    def propsFile = file(propsFilePath) 
 
    def props = new Properties() 
 
    propsFile.withReader { reader -> 
 
     props.load(reader) 
 
    } 
 
    def storeFile = new File(privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile')) 
 
    if (!storeFile.isAbsolute()) { 
 
     storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile()) 
 
    } 
 
    if (!storeFile.exists()) { 
 
     throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath()) 
 
    } 
 
    signingConfig.keyAlias = privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias') 
 
    signingConfig.keyPassword = props.get('keyPassword', signingConfig.keyPassword) 
 
    signingConfig.storeFile = storeFile 
 
    signingConfig.storePassword = props.get('storePassword', signingConfig.storePassword) 
 
    def storeType = props.get('storeType') 
 
    if (!storeType) { 
 
     def filename = storeFile.getName().toLowerCase(); 
 
     if (filename.endsWith('.p12') || filename.endsWith('.pfx')) { 
 
      storeType = 'pkcs12' 
 
     } 
 
    } 
 
    if (storeType) { 
 
     signingConfig.storeType = storeType 
 
    } 
 
} 
 

 
// This can be defined within build-extras.gradle as: 
 
//  ext.postBuildExtras = { ... code here ... } 
 
if (hasProperty('postBuildExtras')) { 
 
    postBuildExtras() 
 
}

После того, как я запустить код и попытаться открыть мое приложение пользовательских клавиатуры получить следующее исключение.

E/BinaryDictionary: Could not load native library jni_latinime 
 
12-06 15:22:01.269 8412-8412/com.KGP.inputmethod.latin E/art: No implementation found for int com.android.inputmethod.latin.BinaryDictionary.openNative(java.nio.ByteBuffer, int, int) (tried Java_com_android_inputmethod_latin_BinaryDictionary_openNative and Java_com_android_inputmethod_latin_BinaryDictionary_openNative__Ljava_nio_ByteBuffer_2II) 
 
12-06 15:22:01.270 8412-8412/com.KGP.inputmethod.latin D/AndroidRuntime: Shutting down VM 
 
12-06 15:22:01.271 8412-8412/com.KGP.inputmethod.latin E/AndroidRuntime: FATAL EXCEPTION: main 
 
                     Process: com.KGP.inputmethod.latin, PID: 8412 
 
                     java.lang.UnsatisfiedLinkError: No implementation found for int com.android.inputmethod.latin.BinaryDictionary.openNative(java.nio.ByteBuffer, int, int) (tried Java_com_android_inputmethod_latin_BinaryDictionary_openNative and Java_com_android_inputmethod_latin_BinaryDictionary_openNative__Ljava_nio_ByteBuffer_2II) 
 
                      at com.android.inputmethod.latin.BinaryDictionary.openNative(Native Method) 
 
                      at com.android.inputmethod.latin.BinaryDictionary.loadDictionary(BinaryDictionary.java:151) 
 
                      at com.android.inputmethod.latin.BinaryDictionary.<init>(BinaryDictionary.java:82) 
 
                      at com.android.inputmethod.latin.Suggest.<init>(Suggest.java:114) 
 
                      at com.android.inputmethod.latin.LatinIME.initSuggest(LatinIME.java:494) 
 
                      at com.android.inputmethod.latin.LatinIME.onCreate(LatinIME.java:399) 
 
                      at android.app.ActivityThread.handleCreateService(ActivityThread.java:2945) 
 
                      at android.app.ActivityThread.access$1900(ActivityThread.java:159) 
 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1467) 
 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
 
                      at android.os.Looper.loop(Looper.java:152) 
 
                      at android.app.ActivityThread.main(ActivityThread.java:5507) 
 
                      at java.lang.reflect.Method.invoke(Native Method) 
 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Ниже моя структура папок проекта: - enter image description here

Мой код класса, где я отправляю LIB: -

static { 
 
\t \t try { 
 
\t \t \t System.loadLibrary("jni_latinime_moo"); 
 
\t \t } catch (UnsatisfiedLinkError ule) { 
 
\t \t \t Log.e("BinaryDictionary", 
 
\t \t \t \t \t "Could not load native library jni_latinime"); 
 
\t \t } 
 
\t }

Я не уверен, что я делаю неправильно здесь. Я очень благодарен, кто когда-нибудь может помочь мне.

+0

вы имели в виду '.so' файл в заглавие? --- Вы смешиваете 32-битные и 64-битные, возможно? – Andreas

+0

О, извините, да, я имею в виду .so файл. Я не уверен, что вы имеете в виду под 32-битным и 64-битным. –

ответ

0

я решил мою проблему, используя эту ссылку: -

stackoverflow.com/questions/21096819/jni-and-gradle-in-android-studio

 Смежные вопросы

  • Нет связанных вопросов^_^