happyj2me
3/21/2019 - 6:32 AM

and-apprtc

1.获取webrtc代码拉取以及编译的工具
cd /home/kevin/webrtc
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=/home/kevin/webrtc/depot_tools:$PATH

2. 获取webrtc-master分支的最新代码
cd /home/kevin/webrtc/linux
fetch --no-hooks webrtc_android
gclient sync
cd src
git checkout master

3. 选择一个release分支来工作,比如72
git checkout -b 72 refs/remotes/branch-heads/72
gclient sync

3.编译
gn gen out/android --args='target_os="android" target_cpu="arm"'
ninja -C out/android

4.生成AppRTCMobile工程 --split-projects --use-gradle-process-resources 这两个不用,否则生成的工程有很多的模块,
  看起来很复杂,而且编译问题难搞定,--canary不指定就是生成适合稳定版本Android Studio用的
build/android/gradle/generate_gradle.py --output-directory $PWD/out/android --target "//examples:AppRTCMobile"

5.使用Android Studio import /home/kevin/webrtc/linux/src/out/android/gradle 工程:
5.1 如果提示使用webrtc的sdk还是其他sdk,选择使用webrtc的
5.2 如果提示是否使用gradle wrapper,选择OK
5.3 删除步骤3生成的一些重复类,比如R.java
    cd /home/kevin/webrtc/linux/src/out/android/gradle/examples/AppRTCMobile
    rm -rf build
    rm extracted-srcjars/org/appspot/apprtc/R.java
    rm extracted-srcjars/org/chromium/base/BuildConfig.java

6. 由于webrtc代码大量使用了lambada表达式,所以最低需要安装jdk-1.8

7. Android Studio build.gradle内容注释掉两行,如下:
// Generated by //build/android/generate_gradle.py

apply plugin: "com.android.application"

android {
    compileSdkVersion 28

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        minSdkVersion 16
        targetSdkVersion 28
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    sourceSets {
        main {
            aidl.srcDirs = []
            assets.srcDirs = []
            java.srcDirs = []
            jni.srcDirs = []
            renderscript.srcDirs = []
            res.srcDirs = []
            resources.srcDirs = []
        }
        test {
            aidl.srcDirs = []
            assets.srcDirs = []
            java.srcDirs = []
            jni.srcDirs = []
            renderscript.srcDirs = []
            res.srcDirs = []
            resources.srcDirs = []
        }
        androidTest {
            aidl.srcDirs = []
            assets.srcDirs = []
            java.srcDirs = []
            jni.srcDirs = []
            renderscript.srcDirs = []
            res.srcDirs = []
            resources.srcDirs = []
        }
        debug {
            aidl.srcDirs = []
            assets.srcDirs = []
            java.srcDirs = []
            jni.srcDirs = []
            renderscript.srcDirs = []
            res.srcDirs = []
            resources.srcDirs = []
        }
        release {
            aidl.srcDirs = []
            assets.srcDirs = []
            java.srcDirs = []
            jni.srcDirs = []
            renderscript.srcDirs = []
            res.srcDirs = []
            resources.srcDirs = []
        }

        main {
            manifest.srcFile "../../../../../examples/androidapp/AndroidManifest.xml"
            java.srcDirs = [
                "../../../../../build/android/buildhooks/java",
                "../../../../../examples/androidapp/src",
                "../../../../../modules/audio_device/android/java/src",
                "extracted-srcjars",
                "../../../../../rtc_base/java/src",
                "../../../../../sdk/android/api",
                "../../../../../sdk/android/src/java",
                "../../../../../third_party/jsr-305/src/ri/src/main/java",
            ]
            java.filter.exclude(
                "org/chromium/build/BuildHooksAndroidImpl.java",
                "org/chromium/build/BuildHooksAndroid.java",
            )
            jniLibs.srcDirs = [
                "symlinked-libs",
            ]
            res.srcDirs = [
                "../../../../../examples/androidapp/res",
                "extracted-res",
            ]
        }
    }
}


dependencies {
    implementation files("../../../lib.java/examples/androidapp/third_party/autobanh/autobanh.jar")
}
afterEvaluate {
    def tasksToDisable = tasks.findAll {
        return (it.name.equals('generateDebugSources')  // causes unwanted AndroidManifest.java
                || it.name.equals('generateReleaseSources')
                || it.name.endsWith('BuildConfig')  // causes unwanted BuildConfig.java
                || it.name.equals('preDebugAndroidTestBuild')
                || it.name.endsWith('Assets')
                || it.name.endsWith('Resources')
                || it.name.endsWith('ResValues')
                || it.name.endsWith('Aidl')
                || it.name.endsWith('Renderscript')
                || it.name.endsWith('Shaders'))
    }
    tasksToDisable.each { Task task ->
      //task.enabled = false
    }
    tasks.withType(JavaCompile) {
      //options.bootClasspath = "[u'/home/kevin/webrtc/linux/src/out/android/lib.java/third_party/android_tools/android.jar']"
    }
}