如何用CLion 导入android 系统项目的代码

很少写博客,没有什么动力啊,大家多支持下。

以前看android代码的时候一直想有一个神器能满足我的要求:

  1. 代码的组织结构不要变化,方便我定位代码的位置
  2. 要有代码高亮,代码补全,自动提示的功能
  3. UI要友好,使用方便

现在终于找到了, 进入正题:

把下面几个文件放到系统根目录下, 然后用 clion File->Open 选中 android_c.iml 文件

android_c.ipr


<project version="4">
  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
  <component name="CidrRootsConfiguration">
    <excludeRoots>
      <file path="$PROJECT_DIR$/.repo" />
      <file path="$PROJECT_DIR$/abi" />
      <file path="$PROJECT_DIR$/art" />
      <file path="$PROJECT_DIR$/bionic" />
      <file path="$PROJECT_DIR$/bootable" />
      <file path="$PROJECT_DIR$/build" />
      <file path="$PROJECT_DIR$/cts" />
      <file path="$PROJECT_DIR$/dalvik" />
      <file path="$PROJECT_DIR$/device" />
      <file path="$PROJECT_DIR$/external" />
      <file path="$PROJECT_DIR$/gen" />
      <file path="$PROJECT_DIR$/kernel" />
      <file path="$PROJECT_DIR$/libnativehelper" />
      <file path="$PROJECT_DIR$/ndk" />
      <file path="$PROJECT_DIR$/out" />
      <file path="$PROJECT_DIR$/packages" />
      <file path="$PROJECT_DIR$/pdk" />
      <file path="$PROJECT_DIR$/platform_testing" />
      <file path="$PROJECT_DIR$/prebuilts" />
      <file path="$PROJECT_DIR$/res" />
      <file path="$PROJECT_DIR$/rkst" />
      <file path="$PROJECT_DIR$/rockdev" />
      <file path="$PROJECT_DIR$/sdk" />
      <file path="$PROJECT_DIR$/tools" />
      <file path="$PROJECT_DIR$/u-boot" />
      <file path="$PROJECT_DIR$/vendor" />
    excludeRoots>
  component>
  <component name="InspectionProjectProfileManager">
    <profile version="1.0">
      <option name="myName" value="Project Default" />
      <inspection_tool class="LossyEncoding" enabled="false" level="WARNING" enabled_by_default="false" />
    profile>
    <version value="1.0" />
  component>
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/android_c.iml" filepath="$PROJECT_DIR$/android_c.iml" />
    modules>
  component>
project>

android_c.iml


<module classpath="CMake" type="CPP_MODULE" version="4" />

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(android_c)
add_definitions(-DANDROID)

set(PROJECT_DIR "path/of/your/android/project")
set(CMAKE_C_COMPILER ${PROJECT_DIR}/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER ${PROJECT_DIR}/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-gcc)

include_directories(kernel/include)
include_directories(prebuilts/ndk/9/platforms/android-19/arch-arm/usr/include)

include_directories(external/libcxx/include)
include_directories(external/libpcap)

include_directories(bionic/libc)
include_directories(bionic/libc/kernel/uapi)
include_directories(bionic/libc/include)
include_directories(bionic/libc/arch-arm/include)
include_directories(bionic/libstdc++/include)
include_directories(bionic/libc/upstream-netbsd/libc/include)
include_directories(bionic/libthread_db/include)
include_directories(bionic/libm/include)


include_directories(frameworks/native/include)
include_directories(frameworks/base/include/)
include_directories(frameworks/av/include/)
include_directories(system/core/include)
include_directories(hardware/libhardware/include)
include_directories(hardware/rockchip/camera/SiliconImage/include)
include_directories(hardware/rockchip/camera/SiliconImage/include/isp_cam_api)
include_directories(hardware/rockchip/camera/SiliconImage/isi/include)

file(GLOB_RECURSE BIONIC_SOURCES "bionic/*.cpp" "bionic/*.c" "bionic/*.cxx" "bionic/*.h")
file(GLOB_RECURSE HARDWARE_SOURCES "hardware/*.cpp" "hardware/*.c" "hardware/*.cxx" "hardware/*.h")
file(GLOB_RECURSE FRAMEWORK_SOURCES "frameworks/*.cpp" "frameworks/*.c" "frameworks/*.cxx" "frameworks/*.h")
file(GLOB_RECURSE SYSTEM_SOURCES "system/*.cpp" "system/*.c" "system/*.cxx" "system/*.h")
file(GLOB_RECURSE LIBCORE_SOURCES "libcore/*.cpp" "libcore/*.c" "libcore/*.cxx" "libcore/*.cc" "libcore/*.h")


add_executable(android_c ${BIONIC_SOURCES} ${LIBCORE_SOURCES} ${HARDWARE_SOURCES} ${FRAMEWORK_SOURCES} ${SYSTEM_SOURCES} )

CMakeLists.txt 中的 PROJECT_DIR , CMAKE_C_COMPILER ,CMAKE_CXX_COMPILER 可能需要修改


文件简单说明

  • .ipr project 文件
  • .iml module 文件
  • .iws workspace 文件(自动生成)
  • CMakeLists.txt clion使用cmake编译

你可能感兴趣的:(android-系统开发)