• 在android上使用 standalone toolchains移植 transmission


    for preview english version, visit here

    1. 1.       为何要用到NDK?

    概括来说主要分为以下几种情况:

    1)              代码的保护,由于apk的java层代码很容易被反编译,而C/C++库反汇难度较大。

    2)              在NDK中调用第三方C/C++库,因为大部分的开源库都是用C/C++代码编写的。

    3)              便于移植,用C/C++写得库可以方便在其他的嵌入式平台上再次使用。

    1. 2.       从官网上下载NDK

    http://developer.android.com/tools/sdk/ndk/index.html

     

    安装后目录如下:

    [dengwei@localhost android-NDK]$ pwd

    /home/dengwei/android-NDK

    [dengwei@localhost android-NDK]$ ls

    build               ndk-build      platforms       RELEASE.TXT  toolchains

    docs                ndk-build.cmd  prebuilt        samples

    documentation.html  ndk-gdb        README_dengwei  sources

    GNUmakefile         ndk-stack      README.TXT      tests

     

    为进行用adb模拟环境调试需要安装android  SDK

    http://developer.android.com/sdk/index.html

     

    安装后目录如下:

    [dengwei@localhost android-SDK]$ pwd

    /home/dengwei/android-SDK

     

            

    1. 3.       安装完android-NDK android-SDK后,home目录下的.bashrc文件修改红色字体部分

    [dengwei@localhost ~]$cat .bashrc

    # .bashrc

     

    # Source global definitions

    if [ -f /etc/bashrc ]; then

            . /etc/bashrc

    fi

     

    # User specific aliases and functions

    export PATH="/usr/local/toolchain_mipsel/bin:$PATH"

    export PATH="/usr/local/toolchain_arm/bin:$PATH"

    #export PATH="/home/dengwei/arm-marvell-linux-gnueabi/bin:$PATH"

    export PATH="/home/dengwei/android-NDK:$PATH"

    export PATH="/home/dengwei/standalone-toolchain/bin:$PATH"

     

    #export PATH="${PATH}:/home/dengwei/android-SDK:"

     

     

    1. 4.       首先需要移植 openssl, curl , libevent ,然后我们才可以移植 transmission.

        移植上述三个项目需各自到其官网下载其源码。

        正确安装移植上述三个项目后的文件结构图 如下图所示:

     

    [dengwei@localhost ~]$ pwd

    /home/dengwei

    [dengwei@localhost ~]$ ls porting_*

    porting_curl:

    bin  include  lib  share

    porting_libevent:

    bin  include  lib  share

    porting_openssl:

    bin  include  lib  ssl

     

    1. 5.       移植 transmission.

         ./configure --host=arm-linux  --enable-cli --enable-daemon --prefix="/home/dengwei/porting_transmission/install" CXX=arm-linux-androideabi-g++ CC=arm-linux-androideabi-gcc  --enable-gtk=no    LIBEVENT_CFLAGS="-I /home/dengwei/porting_libevent/include/ -L/home/dengwei/porting_libevent/lib/"  LIBCURL_CFLAGS="-I /home/dengwei/porting_curl/include/ -L/home/dengwei/porting_curl/lib/" OPENSSL_CFLAGS="-I /home/dengwei/porting_openssl/include/ -L/home/dengwei/porting_openssl/lib/" LDFLAGS="-L/home/dengwei/porting_libevent/lib/ -levent"

     make && make install

     

    有问题参考LDFLAGS

     

    顺利的话,移植完成。

     

    1. 6.       File信息可以看到:

             文件类型已经是ARM的执行文件了

             依赖的是 dynamically linked, 也就是说.so 文件

         

    [dengwei@localhost bin]$ file transmissioncli

    transmissioncli: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

    [dengwei@localhost bin]$ file transmission-daemon

    transmission-daemon: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

    [dengwei@localhost bin]$ pwd

    /home/dengwei/porting_transmission/install/bin

    1. 7.         以下开始在模拟器搭建,会碰到些只读文件系统的错误,但可以解决。

    1)         dynamically linked, means we need .so file, so:

    PC 上adb 所在目录: /home/dengwei/android-SDK/platform-tools/

    ./adb push ~/porting_transmission/install /data/

     

      in adb shell,use su and cat to copy file to  /system/lib which store .so file

     

    # cat /data/lib/libevent-1.4.so.2 > ./libevent-1.4.so.2

    cannot create ./libevent-1.4.so.2: read-only file system

    # su

    # adb remount

    * daemon not running. starting it now on port 5038 *

    * daemon started successfully *

     

    remount succeeded

    #

     

           PC 上adb 所在目录: /home/dengwei/android-SDK/platform-tools/

    ./adb push ~/porting_libevent/lib/libevent-1.4.so.2 /data/lib/

    ./adb push ~/porting_curl/lib/libcurl.so.5 /data/lib/

     in adb shell

    # pwd

    /system/lib

    # cat /data/lib/libevent-1.4.so.2 > ./libevent-1.4.so.2

    # cat /data/lib/libcurl.so.5 > ./libcurl.so.5

     

      in adb shell

     

    # cat /data/lib/libcurl.so.5 > ./libcurl.so.5

    # /data/bin/transmission-daemon

    # ps

    USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME

    root      530   1     5424   984   ffffffff 40026c94 S /data/bin/transmission-daemon

    # /data/bin/transmission-daemon --version

    Transmission 2.04 (11151)

     

     

    2)         最后,我们访问以下web界面以确认是否transmission工作完好。

    a)         访问web前,我们需要设置环境变量   TRANSMISSION_HOME (in order to find setting.json and locate torrent resume dir )

    TRANSMISSION_WEB_HOME (in order to find web files) environment variables, 否则我们只能得到404错误。

    b)         修改环境变量:

    export TRANSMISSION_HOME=/data/transmission

    export TRANSMISSION_WEB_HOME=/data/transmission/share/transmission/web

     

    #ps

       root      556   1     4400   1000  ffffffff 40026c94 S /data/bin/transmission-daemon

                 

    root      5724789003480000000040010458 R ps

    # kill -9 556

    # echo $TRANSMISSION_WEB_HOME

    /data/share/transmission/web

    # /data/bin/transmission-daemon -u root -v toor -w /sdcard/BT

     

    c)         测试webbrowser访问:http://127.0.0.1:9091 redirect http://127.0.0.1:9091/transmission/web

     

    # /data/bin/transmission-remote --auth=root:toor -a /sdcard/Download/9203e0ebf3e5382dce42ca5add007a32bc0d9bcb.torrent

    localhost:9091 responded: "success"

    d)         好,现在我们可以看到 transmission web UI

     

     ==========================================

    1. 8.       在真正开发板上:what we need to do :

     

    1)         mkdir /data/transmission/

    2)         mkdir /data/lib/

    3)         copy porting_transmission/install to board /data/transmission and make them executable by running

    chmod 0777 ./* , in directory /data/transmission

    4)         copy 2 .so file to /data/lib/

    5)         su

    6)         #mount -o remount,rw /

    7)         #copy files in /data/lib/ to /system/lib/

    8)         #edit /init.rc by adding :

    export TRANSMISSION_HOME=/data/transmission

    export TRANSMISSION_WEB_HOME=/data/transmission/share/transmission/web

    9)         also we run 2 export command above

    10)     start transmission by /data/transmission/bin/transmission-daemon -u root -v toor -w /sdcard/BT

    11)     /data/bin/transmission-remote --auth=root:toor -a /sdcard/Download/9203e0ebf3e5382dce42ca5add007a32bc0d9bcb.torrent

    localhost:9091 responded: "success"

     

    现在,transmission正常工作。

     

     

    1. 9.        附:对应的脚本以省略每次手动操作:

    1)         start.sh

    #!/bin/sh

    export TRANSMISSION_HOME=/data/transmission

    echo $TRANSMISSION_HOME

    export TRANSMISSION_WEB_HOME=/data/transmission/share/transmission/web

    echo $TRANSMISSION_WEB_HOME

    /data/transmission/bin/transmission-daemon -u root -v toor -w /sdcard/BT -g /data/transmission

     

    2)         start_transmission.sh

    #!/bin/sh

    export TRANSMISSION_HOME=/data/transmission

    echo $TRANSMISSION_HOME

    export TRANSMISSION_WEB_HOME=/data/transmission/share/transmission/web

    echo $TRANSMISSION_WEB_HOME

    /data/transmission/bin/transmission-daemon -u root -v toor -w /sdcard/BT -g /data/transmission

    ln -s /data/transmission/ /opt

     

    3)         start_serverM.sh

    #!/bin/sh

    mkdir -p /tmp/hdd/volumes/HDD1/BT

    mkdir -p /tmp/hdd/volumes/HDD1/torrents

    /data/BTControl/serverM > /tmp/hdd/volumes/HDD1/ser_log&

     

     

    1. 10.   参考:

    1)         Stuck on compiling (cross-compiling using scratchbox).

    https://forum.transmissionbt.com/viewtopic.php?f=2&t=13495&p=60564&hilit=undefined+reference+to+%60event_add%27#p60564

     

    2)         android文件系统结构分析

    http://hi.baidu.com/xinyang_wei/item/835b165739f7fa3433e0a95d

    3)         cross-device link问题求助

    http://bbs.gfan.com/android-3707763-1-1.html

     

    4)         android上使用 stand-alone toolchains移植 transmission

    http://www.cnblogs.com/no7dw/archive/2012/10/08/2715424.html

     

    5)         关于transmission-remote   transmission-daemon 用法参考 transmission 的 –h 选项的打印文档。

  • 相关阅读:
    POJ 2585 Window Pains 拓扑排序
    hrbust 2069 萌萌哒十五酱的衣服~ stl
    CodeForces 785D Anton and School
    CodeForces 816C Karen and Game
    CodeForces 758C Unfair Poll 模拟
    CodeForces 746D Green and Black Tea 有坑
    CodeForces 811C Vladik and Memorable Trip dp
    栈 队列 (面向对象列表实现)
    员工信息表 信息检索(模糊查询)
    员工信息表 查询 周末写(很简单)
  • 原文地址:https://www.cnblogs.com/no7dw/p/2889796.html
Copyright © 2020-2023  润新知