ICU Library - AlphabeticIndex类和缺少的jni函数

时间:2016-03-10 10:31:29

标签: android android-studio android-ndk icu android-launcher

我目前正在使用某个应用程序并尝试使其与较低的api版本兼容。我已设法使其与 Android Api Level 21 Android Api Level 18 兼容。

我目前仍然坚持 17 。修复了android api 18中引入的所有新方法后,程序编译但不运行。

发生了什么

应用程序(启动程序)在开始启动时发出关于缺少JNI函数的通知。该应用程序在api级别18上编译并正常工作,但它在api级别17上不起作用,尽管它编译。<​​/ p>

应用程序在android api级别17失败并且 peer 变量未被分配,根据android监视器,函数 create 未实现。一旦调用该应用程序,应用程序就会失败。

奇怪的是,在api 18级它运行正常。但函数create永远不会被调用,虽然它是唯一改变变量值的函数,但变量确实会改变值。

我搜索过的内容

搜索并查看 Icu库的文档。它出现在 AlphabeticIndex 类中,根本没有创建函数。

在谷歌搜索创建方法和 AlphabeticIndex ,很多启动器和应用程序正在使用与我现在相同的文件。因此,拥有这些缺少jni函数并非巧合。

在整个应用程序中放置断点,并在Api Level 17上看到,在构造函数上调用该函数。它一旦进入创建方法就会失败,并且变量 peer 不会更改。

在android api level 18上,类构造函数被调用但它没有运行。没有来自 Log.e 语句的消息即将出现,而在重新布局时,它会跳过构造函数和函数,只是更改变量 peer 值。

更改变量的函数只有一个用法,就是您在此处看到的用法。

对变量 peer 进行观看,我发现价值会发生变化,但我显然不明白为什么。任何想法或建议?你们之前有过ICU图书馆经验的人吗?

代码

/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package libcore.icu;

import android.util.Log;

import java.util.Locale;

/**
 * Exposes icu4c's AlphabeticIndex.
 */

public final class AlphabeticIndex {
 // Breakpoint here
  /**
   * Exposes icu4c's ImmutableIndex (new to icu 51). This exposes a read-only,
   * thread safe snapshot view of an AlphabeticIndex at the moment it was
   * created, and allows for random access to buckets by index.
   */

  public static final class ImmutableIndex {
    private long peer;

    private ImmutableIndex(long peer) {
      this.peer = peer;
    }

    @Override protected synchronized void finalize() throws Throwable {
      try {
        destroy(peer);
        peer = 0;
      } finally {
        super.finalize();
      }
    }

    /**
     * Returns the number of the label buckets in this index.
     */
    public int getBucketCount() {
      return getBucketCount(peer);
    }

    /**
     * Returns the index of the bucket in which 's' should appear.
     * Function is synchronized because underlying routine walks an iterator
     * whose state is maintained inside the index object.
     */
    public int getBucketIndex(String s) {
      return getBucketIndex(peer, s);
    }

    /**
     * Returns the label for the bucket at the given index (as returned by getBucketIndex).
     */
    public String getBucketLabel(int index) {
      return getBucketLabel(peer, index);
    }

    private static native int getBucketCount(long peer);
    private static native int getBucketIndex(long peer, String s);
    private static native String getBucketLabel(long peer, int index);
  }
 // watch here
  private long peer;

  /**
   * Creates a new AlphabeticIndex for the given locale.
   */



  public AlphabeticIndex(Locale locale) {

    Log.e("Debbugingthisone", "Method called");
    try {
      // breakpoint here
      peer = create(locale.toString());
    }
    catch(Exception e){
      Log.e("Debuggingthisone", "Problem" + e.toString());
    }
    Log.e("Debuggingthisone", "Constructor call finished");
  }


  @Override protected synchronized void finalize() throws Throwable {
    try {
      destroy(peer);
      peer = 0;
    } finally {
      super.finalize();
    }
  }

  /**
   * Returns the max number of the label buckets allowed in this index.
   */
  public synchronized int getMaxLabelCount() {
    return getMaxLabelCount(peer);
  }

  /**
   * Sets the max number of the label buckets in this index.
   * (ICU 51 default is 99)
   */
  public synchronized AlphabeticIndex setMaxLabelCount(int count) {
    setMaxLabelCount(peer, count);
    Log.e("Arlind","peer vlera " + peer);
    return this;
  }

  /**
   * Adds the index characters from the given locale to the index.
   * The labels are added to those that are already in the index;
   * they do not replace the existing index characters.
   * The collation order for this index is not changed;
   * it remains that of the locale that was originally specified
   * when creating this index.
   */
  public synchronized AlphabeticIndex addLabels(Locale locale) {
    addLabels(peer, locale.toString());
    return this;
  }

  /**
   * Adds the index characters in the range between the specified start and
   * end code points, inclusive.
   */
  public synchronized AlphabeticIndex addLabelRange(int codePointStart, int codePointEnd) {
    addLabelRange(peer, codePointStart, codePointEnd);
    return this;
  }

  /**
   * Returns the number of the label buckets in this index.
   */
  public synchronized int getBucketCount() {
    return getBucketCount(peer);
  }

  /**
   * Returns the index of the bucket in which 's' should appear.
   * Function is synchronized because underlying routine walks an iterator
   * whose state is maintained inside the index object.
   */
  public synchronized int getBucketIndex(String s) {
    return getBucketIndex(peer, s);
  }

  /**
   * Returns the label for the bucket at the given index (as returned by getBucketIndex).
   */
  public synchronized String getBucketLabel(int index) {
    return getBucketLabel(peer, index);
  }

  /**
   * Returns an ImmutableIndex created from this AlphabeticIndex.
   */
  public synchronized ImmutableIndex getImmutableIndex() {
    return new ImmutableIndex(buildImmutableIndex(peer));
  }


  private static native long create(String locale);
  private static native void destroy(long peer);
  private static native int getMaxLabelCount(long peer);
  private static native void setMaxLabelCount(long peer, int count);
  private static native void addLabels(long peer, String locale);
  private static native void addLabelRange(long peer, int codePointStart, int codePointEnd);
  private static native int getBucketCount(long peer);
  private static native int getBucketIndex(long peer, String s);
  private static native String getBucketLabel(long peer, int index);
  private static native long buildImmutableIndex(long peer);
}

0 个答案:

没有答案