【环境搭建005】UBUNTU13.04 android4.08 源码编译实践中遇到的问题

基本编译配置:

ubuntu 13 / android 4.0 SDK / eclips / gcc 4.4 / g++ 4.4 / jdk1.6.0_27


首先,确认你的各个工具包是否安装正确,而需要安装正确,首先要确认你的update list是不是最新而且完备。

你需要用apt-get update 来确认一下你的安装源是不是完备,如果没得到done的结果基本上你就是没做对,后面你就会遇到各种各样因为缺失库而出现的各种古怪问题。

ubuntu 的右上角有一个Updates Available……

先在这里面选一个中国的源,

【hsy75】

注意,不要选择更新整个系统,而是选择“Setting”。然后,选择other/.china下的东西。

#apt-get update

如果,一直更新失败,也许是原来的源冲突了,需要做下面几步:


ubuntu apt-get update失败
1.出现错误:E:Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
出现这个问题的原因可能是有另外一个程序正在运行,导致资源被锁不可用。而导致资源被锁的原因,可能是上次安装时没正常完成,而导致出现此状况。
 
解决方法:把 /var/lib/apt/lists 中的文件全部删掉
输入以下命令
sudo rm /var/cache/apt/archives/lock
 
sudo rm /var/lib/dpkg/lock
 
之后再安装想装的包,即可解决
2.出现错误:E: Some index files failed to download. They have been ignored, or old ones used instead.
解决方法:
To upgrade a really old Ubuntu release, we first need to edit our sources.
list and change all(xx.)archive.ubuntu.com to old-releases.ubuntu.com.
 
   $ sudo emacs /etc/apt/sources.list
So your lines should instead of
   deb http://archive.ubuntu.com/ubuntu jaunty main restricted universe
look like
   deb http://old-releases.ubuntu.com/ubuntu jaunty main restricted universe
In this example I use jaunty release. But it works the same on other releases.
Now update the repos  
   $ sudo apt-get update


1  缺少库的编译错误

dalvik/vm/native/dalvik_system_Zygote.cpp:222:43: error: ‘setrlimit’ was not declared in this scope
 err = setrlimit(contents[0], &rlim);
解决办法:

add #include <sys/resource.h> to dalvik/vm/native/dalvik_system_Zygote.cpp

详细参考:

http://mjanja.co.ke/2013/04/fix-for-dalvik-compile-error-on-cyanogenmod-9/


2 makefile 路径的问题

因为makefile 大概一般找的都/usb/bin /usr/lib

2.1 ubuntu 缺少统一的路径配置,或者由于多个不同的包没有配置,所以编译系统找不到:

如何你把他搞成绝对或者相对的路径,那你会面对另外一个问题,那就是你编译系统可以顺利找到东西,可是ubuntu系统则搞不定了。。。

所以最好最有效的方法,还是利用ubuntu提供的工具来解决,只是设定优先级,然后,系统会主动觉得该用哪个,那个不好用(API)就换一个


这里举例javadoc,其他还有java,javac,javah,gcc,g++等类似这种配置

实际问题如下:

Docs droiddoc: out/target/common/docs/doc-comment-check
Docs droiddoc: out/target/common/docs/api-stubs
host layoutlib_create: out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar
-rw-r--r-- 1 root root 9240987  4月  4 00:30 out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar
/bin/bash: line 2: javadoc: command not found
/bin/bash: line 2: javadoc: command not found
make: *** [out/target/common/docs/api-stubs-timestamp] Error 45
make: *** Waiting for unfinished jobs....
make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45

解决办法:

sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_27/bin/javadoc 300

其他的配置举例:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_27/bin/java 300

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_27/bin/javac 300

sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_27/bin/jar  300

然后通过

sudoupdate-alternatives --config java

命令检查 java 的配置

hsy@ubuntu:/usr/lib/jvm/jdk1.6.0_27/bin$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/jdk1.6.0_27/bin/java               300       manual mode

原来的选择是openjdk

Press enter to keep the current choice[*], or type selection number:
输入我们刚才的配置的2 选项,把系统默认java设为这个

hsy@ubuntu:/usr/lib/jvm/jdk1.6.0_27/bin$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                           Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1071      manual mode
* 2            /usr/lib/jvm/jdk1.6.0_27/bin/java               300       manual mode

接下来是有关gcc ,g++的设定,和上节类似;

hsy@ubuntu:/usr/lib/jvm/jdk1.6.0_27/bin$ sudo update-alternatives --config gcc
sudoupdate-alternatives: command not found

说明gcc 还没配置,据说android 应该用 gcc 4.4

看看 我们有没有hsy@ubuntu:/usr/bin$ ls -all *gcc*
-rwxr-xr-x 1 root root    428 May  7  2006 c89-gcc
-rwxr-xr-x 1 root root    454 Apr 11  2011 c99-gcc
lrwxrwxrwx 1 root root      7 Feb 13 06:43 gcc -> gcc-4.7
-rwxr-xr-x 1 root root 527596 Apr 15  2013 gcc-4.7
-rwxr-xr-x 1 root root  22000 Apr 15  2013 gcc-ar-4.7
-rwxr-xr-x 1 root root  22000 Apr 15  2013 gcc-nm-4.7
-rwxr-xr-x 1 root root  22000 Apr 15  2013 gcc-ranlib-4.7
装吧

hsy@ubuntu:/usr/bin$ sudo apt-get install gcc-4.4


sudo apt-get install gcc-4.4
sudo apt-get install gcc-4.4-multilib
sudo apt-get install g++-4.4
sudo apt-get install g++-4.4-multilib
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4  40
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7  60

hsy@ubuntu:/usr/bin$ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gcc-4.7   60        auto mode
  1            /usr/bin/gcc-4.4   40        manual mode
  2            /usr/bin/gcc-4.7   60        manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/gcc-4.4 to provide /usr/bin/gcc (gcc) in manual mode

hsy@ubuntu:/usr/bin$ ls -all g++*
lrwxrwxrwx 1 root root     21 Apr  6 19:30 g++ -> /etc/alternatives/g++
-rwxr-xr-x 1 root root 224576 Jan 30  2013 g++-4.4
-rwxr-xr-x 1 root root 527596 Apr 15  2013 g++-4.7


sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4  40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7  60

hsy@ubuntu:/usr/bin$ sudo update-alternatives --config g++
There are 2 choices for the alternative g++ (providing /usr/bin/g++).

  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-4.7   60        auto mode
  1            /usr/bin/g++-4.4   40        manual mode
  2            /usr/bin/g++-4.7   60        manual mode

Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/g++-4.4 to provide /usr/bin/g++ (g++) in manual mode

至此编译需要的各种编译包已经完成自动选择配置

至于很多人说的要修改 /etc/profile 或者 /etc/enviroment 之类

这个也许有效,但是非常麻烦,还有考虑各个配置的作用域,很难理解!

笔者经过试验完全没有必要 可以正常编译生成正常的文件。

3 虚拟机内存设定导致的编译问题

编译android遇到java虚拟机堆内存不够的问题

问题一:

UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:269)
    at com.android.dx.command.dexer.Main.run(Main.java:240)
    at com.android.dx.command.dexer.Main.main(Main.java:174)
    at com.android.dx.command.Main.main(Main.java:95)
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex] Error 3
make: *** Deleting file `out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex'
make: *** Waiting for unfinished jobs....
true
true


问题二:


target Dex: framework
make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/noproguard.classes-with-local.dex] Killed

解决办法:

修改definitions.mk文件 此文件位于build/core/目录下

修改变量 :transform-classes.jar-to-dex中的-JXms16M -JXmx1024M

ref:


--http://blog.csdn.net/ydt_lwj/article/details/8468272


4使用Android的DX工具编译Class文件出现no classfiles specified问题

target Dex: core
Copy: apicheck (out/host/linux-x86/obj/EXECUTABLES/apicheck_intermediates/apicheck)
Install: out/target/product/x210/system/lib/libc.so
target SharedLib: libstdc++ (out/target/product/x210/obj/SHARED_LIBRARIES/libstdc++_intermediates/LINKED/libstdc++.so)
error: no command specified
usage:
  dx --dex [--debug] [--verbose] [--positions=<style>] [--no-locals]
  [--no-optimize] [--statistics] [--[no-]optimize-list=<file>] [--no-strict]
  [--keep-classes] [--output=<file>] [--dump-to=<file>] [--dump-width=<n>]
  [--dump-method=<name>[*]] [--verbose-dump] [--no-files] [--core-library]
  [--num-threads=<n>]
  [<file>.class | <file>.{zip,jar,apk} | <directory>] ...
    Convert a set of classfiles into a dex file, optionally embedded in a
    jar/zip. Output name must end with one of: .dex .jar .zip .apk. Positions
    options: none, important, lines.
  dx --annotool --annotation=<class> [--element=<element types>]
  [--print=<print types>]
  dx --dump [--debug] [--strict] [--bytes] [--optimize]
  [--basic-blocks | --rop-blocks | --ssa-blocks | --dot] [--ssa-step=<step>]
  [--width=<n>] [<file>.class | <file>.txt] ...
    Dump classfiles, or transformations thereof, in a human-oriented format.
  dx --junit [-wait] <TestClass>
    Run the indicated unit test.
  dx --find-usages <file.dex> <declaring type> <member>
    Find references and declarations to a field or method.
    declaring type: a class name in internal form, like Ljava/lang/Object;
    member: a field or method name, like hashCode
  dx -J<option> ... <arguments, in one of the above forms>
    Pass VM-specific options to the virtual machine that runs dx.
  dx --version
    Print the version of this tool (1.7).
  dx --help
    Print this message.
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex] Error 1
make: *** Waiting for unfinished jobs....
target SharedLib: libm (out/target/product/x210/obj/SHARED_LIBRARIES/libm_intermediates/LINKED/libm.so)


此问题没有解决,可能是和虚拟机的配置有关,例如
VT技术

但是也许是小节6描述的那样,也可能是虚拟机的内存过小,或者不够用造成的。

解决的办法看小结6

5 java相关问题

5.1

hsy@ubuntu:~/x210/x210_ics_rtm_v13$ sudo ./mk -s
build/core/config.mk:268: *** Error: could not find jdk tools.jar, please install JDK6, which you can download from java.sun.com.  Stop.

6 虚拟机的内存不足导致的编译问题

有各种各样的报错表现,例如小结4描述的错误

6.1 绝大多数报错包含如下信息:

make: *** Waiting for unfinished jobs....

6.2 也有报错说是

g++ bug 需要提交的,其实也是内存不够用导致的未知错误


解决的办法很简单:增加内存。如果没有的话,也可以解决

那就是重新启动vmware 虚拟机,然后再编译一次,这样前面的内存占用会被释放出来

然后,你会再出现一个非常诡异的错误,然后地方和上次不同,

重新启动vm,再继续,再来,直到编译结束。



frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]


【修改的地方可能有以下这些】

 解决办法:  frameworks/base/tools/aapt/Android.mk
       在第31行增加:
       LOCAL_CFLAGS += -Wno-format-y2k -fpermissive


2

解决办法:在 development/tools/emulator/opengl/Android.mk
    增加  '-fpermissive' 到25行:
       EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive

3

Fix:
vi frameworks/base/libs/utils/Android.mk

Add '-fpermissive' to line 64:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive


4

vi frameworks/base/libs/rs/Android.mk


Add '-fpermissive' to line 183
LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive


external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:132:9: note: declarations in dependent base ‘fst::VectorFstBaseImpl<fst::CacheState<fst::GallicArc<fst::StdArc, (fst::StringType)0u> > >’ are not found by unqualified lookup
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:132:9: note: use ‘this->SetState’ instead
external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:11: error: ‘SetState’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

【hsy75案:步骤1

sudo wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"

【记录】

--2014-12-17 20:26:55--  https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
Resolving github.com (github.com)... 192.30.252.130
Connecting to github.com (github.com)|192.30.252.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff’


    [  <=>                   ] 13,142      48.8KB/s   in 0.3s   


2014-12-17 20:26:57 (48.8 KB/s) - ‘4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff’ saved [13142]

hsy75案:步骤2】

hsy@ubuntu:~/x210_ics_rtm_v13/external/srec$ sudo patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff

【记录】

patching file tools/thirdparty/OpenFst/fst/lib/cache.h
patching file tools/thirdparty/OpenFst/fst/lib/compose.h
patching file tools/thirdparty/OpenFst/fst/lib/const-fst.h
patching file tools/thirdparty/OpenFst/fst/lib/determinize.h
patching file tools/thirdparty/OpenFst/fst/lib/factor-weight.h
patching file tools/thirdparty/OpenFst/fst/lib/map.h
patching file tools/thirdparty/OpenFst/fst/lib/vector-fst.h

【hsy75案:步骤3】

hsy@ubuntu:~/x210_ics_rtm_v13/external/srec$ sudo rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff

[内存不足】

android arm-linux-androideabi-gcc: Internal error: Killed (program cc1)

arm-linux-androideabi-g++: Internal error: Killed (program cc1plus)

【解决】加大内存设置,或者在编一次


dalvik/vm/native/dalvik_system_Zygote.cpp: In function ‘int setrlimitsFromArray(ArrayObject*)’:
dalvik/vm/native/dalvik_system_Zygote.cpp:194:19: error: aggregate ‘setrlimitsFromArray(ArrayObject*)::rlimit rlim’ has incomplete type and cannot be defined
dalvik/vm/native/dalvik_system_Zygote.cpp:217:43: error: ‘setrlimit’ was not declared in this scope
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libdvm_intermediates/native/dalvik_system_Zygote.o] Error 1




external/gtest/src/../include/gtest/gtest-param-test.h:1185:28:   required from here
external/gtest/src/../include/gtest/internal/gtest-param-util-generated.h:77:26: error: ‘ValuesIn’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

Two fixes required:
1)
vi external/gtest/src/Android.mk


Add '-fpermissive' to lines 52 and 70 (both lines contain same info)
LOCAL_CFLAGS += -O0 -fpermissive


2)
vi external/gtest/include/gtest/internal/gtest-param-util.h


Add '#include <stddef.h>' to list of includes as shown:
#include <vector>
#include <cstddef>
#include <gtest/internal/gtest-port.h>





1 编译Android Source时碰到的问题

http://blog.csdn.net/zaizaishan/article/details/8950707


2 Android编译问题总结

http://blog.csdn.net/yyhzpk/article/details/7078385

3 Ubuntu安装Sun JDK及如何设置默认java JDK

http://blog.sina.com.cn/s/blog_437ff56b0100tfi5.html



any discusstion?

QQ:QQ 1624673069



你可能感兴趣的:(【环境搭建005】UBUNTU13.04 android4.08 源码编译实践中遇到的问题)