Android Studio编译开源项目Bypass(NDK+B

2015-09-10  本文已影响0人  no0one

最近在研究安卓的OTA rom,找到一个开源的项目https://github.com/MatthewBooth/OTAUpdates 其中用到了bypass。
bypass:Skip the HTML, Bypass takes markdown and renders it directly on Android and iOS.

使用Android Studio 1.3.2导入项目编译时出错:Error:(3, 31) 错误: 程序包in.uncod.android.bypass不存在。
这个包在src_bypass目录下,AS并没有导入这个目录。bypass需要用到NDK来编译。项目的Building说明是针对linux下Eclipse的,我用的是Window下AS,刚学Android,不知道怎么配置。
偷懒找到一个使用的AS的bypass项目:https://github.com/actorapp/bypass 导入项目后,出现以下问题:

1.未设置NDK的路径

Error:Execution failed for task ':library:ndkBuild'. > A problem occurred starting process 'command 'null/ndk-build''
配置NDK的的安装路径即可。
1)设置环境变量:新增ANDROID_NDK_HOME键值为Android NDK安装目录,在PATH末尾增加;%ANDROID_NDK_HOME%

或者2)在AS的project structure设置,如下图:


2. 调用的ndk-build命令不对

Error:Execution failed for task ':library:ndkBuild'.> A problem occurred starting process 'command 'D:\androidDev\android-ndk-r10e/ndk-build''

stackoverflow上找到原因,build.gradle文件中

taskndkBuild(type: Exec,description:'Compile JNI source via NDK') {
    defndkDir =project.plugins.findPlugin('com.android.library').sdkHandler.ndkFolder
    workingDir"$projectDir/src/main/jni"
    commandLine"$ndkDir/ndk-build"
}

commandLine"$ndkDir/ndk-build"这一行windows下应该用ndk-build.cmd

3. 找不到boost库文件

项目Readme中有说明

Manual Build
Make sureANDROID_NDK_HOMEis correctly set to the root directory of your NDK installation. Also, if Boost lives in a non-standard directory (or you're on Windows) you'll need to setBYPASS_INCLUDE_PATH to its parent directory.

设置环境变量:新增BYPASS_INCLUDE_PATH键值为boost的安装目录,在PATH末尾增加;%BYPASS_INCLUDE_PATH%

折腾好久,终于编译通过!


Log开关的使用

代码中有一段Benchmark耗时的打印输出

public class BenchmarkActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    TextView text = (TextView) findViewById(R.id.demoText);

    TimingLogger timings = new TimingLogger("Bypass", "onCreate");

    String readme = loadFile();

    timings.addSplit("read raw");

    Bypass bypass = new Bypass(BenchmarkActivity.this);

    timings.addSplit("instantiated Bypass");

    CharSequence string = bypass.markdownToSpannable(readme);

    timings.addSplit("convert to spannable");
    timings.dumpToLog();

    text.setText(string);
    //Allows link clicking
    text.setMovementMethod(LinkMovementMethod.getInstance());
    }
    ......
}

logcat中却看不到。调试跟踪发现这个打印是通过Log.isLoggable来控制开关。在adb shell中设置属性setprop log.tag.Bypass VERBOSE打开打印输出或者写在local.properties中,就可以看到打印输出了。

09-07 09:24:12.111 25845-25845/in.uncod.android.bypass.test D/Bypass﹕ onCreate: begin
09-07 09:24:12.111 25845-25845/in.uncod.android.bypass.test D/Bypass﹕ onCreate: 1 ms, read raw
09-07 09:24:12.111 25845-25845/in.uncod.android.bypass.test D/Bypass﹕ onCreate: 29 ms, instantiated Bypass
09-07 09:24:12.111 25845-25845/in.uncod.android.bypass.test D/Bypass﹕ onCreate: 11 ms, convert to spannable
09-07 09:24:12.111 25845-25845/in.uncod.android.bypass.test D/Bypass﹕ onCreate: end, 41 ms

上一篇下一篇

猜你喜欢

热点阅读