DreamCamera2移植AndroidStudio指南

1.将服务器中DreamCamera2代码复制到本地电脑

s_unisoc_22avendorsprdplatformpackagesappsDreamCamera2

2.下载build.gradle对应版本Android Studio 4.1.1

https://developer.android.google.cn/studio/archive

3.用Android Studio 4.1.1打开DreamCamera2项目,如出现gradle无法下载的情况,请自备梯子
File > Open… > DreamCamera2 > New Window > OK > New Window

4.连接平板电脑,点击Run “DreamCamera2”

5.出现Duplicate resources报错,报错文件为资源key同名冲突,注释一个即可
资源文件一:resvaluesdream_camera_arrays_photo_part.xml
资源文件二:resvaluesdream_camera_arrays_video_part.xml
同名key为:pref_camera_filter_display_key_array
对比发现同名key对应内容也一致,因些注释上述两个资源文件中的一个pref_camera_filter_display_key_array即可
这里我们注释dream_camera_arrays_video_part.xml中的pref_camera_filter_display_key_array

6.再次点击Run “DreamCamera2”

7.出现依赖缺失报错如下:
Transform’s input file does not exist: …DreamCamera2studio_libsandroid-ex-camera2-utils.jar

8.去android12源码out目录使用find out -name "android-ex-camera2-utils.jar"可快速查找到该文件所在位置

out/soong/.intermediates/frameworks/ex/camera2/utils/android-ex-camera2-utils/android_common/javac/android-ex-camera2-utils.jar
out/soong/.intermediates/frameworks/ex/camera2/utils/android-ex-camera2-utils/android_common/javac/android-ex-camera2-utils.jar.rsp
out/soong/.intermediates/frameworks/ex/camera2/utils/android-ex-camera2-utils/android_common/turbine/android-ex-camera2-utils.jar
out/soong/.intermediates/frameworks/ex/camera2/utils/android-ex-camera2-utils/android_common/turbine/android-ex-camera2-utils.jar.rsp
out/soong/.intermediates/frameworks/ex/camera2/utils/android-ex-camera2-utils/android_common/turbine-combined/android-ex-camera2-utils.jar

这里我们使用javac/android-ex-camera2-utils.jar文件,并将其放入编译报错所在路径studio_libs中

9.再次点击Run “DreamCamera2”

10.出现类缺失报错如下:
错误: 找不到符号
符号: 类 SystemProperties;
位置: 程序包 android.os
此类为framework.jar中的类,这里我们他用find out -name “framework-minus-apex.jar”

out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/aligned/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/combined/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/dex/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/hiddenapi/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/hiddenapi/unaligned/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/jarjar/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/turbine/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/turbine/framework-minus-apex.jar.rsp
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/turbine-combined/framework-minus-apex.jar
out/soong/.intermediates/frameworks/base/framework-minus-apex/android_common/turbine-jarjar/framework-minus-apex.jar

这里的们选一个文件最大的combined/framework-minus-apex.jar,并将其放入build.gradle文件中描述的目录,并重命名为framework.jar

options.compilerArgs.add("-Xbootclasspath/p:${ANDROID_TOP}/unisoc_framework/framework.jar")

11.再次点击Run “DreamCamera2”

12.出现已有软件版本号更新报错:The device already has a newer version of this application.
通过下面命令可以监控打开app的包名

C:UsersWJS>adb shell am monitor 
Monitoring activity manager...  available commands:
(q)uit: finish monitoring
** Activity starting: com.android.camera2

通过包名获取apk安装位置

C:UsersWJS>adb shell pm path com.android.camera2
package:/system_ext/app/DreamCamera2/DreamCamera2.apk

将apk下载到电脑上

C:UsersWJS>adb pull /system_ext/app/DreamCamera2/DreamCamera2.apk .
/system_ext/app/DreamCamera2/DreamCamera2.apk: 1 file pulled, 0 skipped. 32.6 MB/s (7698606 bytes in 0.225s)

将apk拖入Android Studio中进行反编译可获取到其:

    android:versionCode="20002000"
    android:versionName="2.0.002"

将上述参数写入build.gradle中,同时点击Sync Now

11.再次点击Run “DreamCamera2”

12.签名不一致报错:The device already has an application with the same package but a different signature.
jks签名文件生成方法:

openssl pkcs8 -inform DER -nocrypt -in "platform.pk8" -out "key"
openssl pkcs12 -export -in "platform.x509.pem" -inkey "key" -out "p12" -password pass:123456 -name platform
openssl x509 -noout -fingerprint -in "platform.x509.pem"
keytool -importkeystore -deststorepass 123456 -destkeystore "platform.jks" -srckeystore "p12" -srcstoretype PKCS12 -srcstorepass 123456

platform.pk8和platform.x509.pem可以在build argetproductsecurity(debug签名)或者vendorsprd
eleaseapk_key(release签名)找到
将生成的jks签名文件放入DreamCamera2/key目录中

在build.gradle中android节点下添加如下内容:

android {
    signingConfigs {
        bnd {
            storeFile file('key/bnd/platform.jks')
            storePassword '123456'
            keyPassword '123456'
            keyAlias 'platform'
        }
    }
	...
    buildTypes {
        ...
        debug {
            ...
            signingConfig signingConfigs.bnd
        }
    }
}

完成后点击Sync Now

13.再次点击Run “DreamCamera2”, 成功使用Android Studio安装DreamCamera2到平板电脑上,并支持实时调试