本文是在上文6. Android10向系统注册service访问硬件抽象层(HAL)模块的基础上进行的,虚拟机环境就是上文结束时的环境。
创建app首先在windows下使用Android studio创建Hello项目
修改MainActivity.java
package com.test.hello;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.IHelloService;
import android.os.ServiceManager;
public class MainActivity extends AppCompatActivity {
final String TAG = "hello!";
Button btn_write = null;
Button btn_read = null;
TextView text_result = null;
EditText text_input = null;
private IHelloService helloService = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_write = (Button) findViewById(R.id.btn_w);
btn_read = (Button) findViewById(R.id.btn_r);
text_result = (TextView) findViewById(R.id.text_result);
text_input = (EditText) findViewById(R.id.text_input);
helloService = IHelloService.Stub.asInterface(
ServiceManager.getService("hello"));
btn_write.setonClickListener(new View.onClickListener() {
@Override
public void onClick(View v) {
try{
helloService.wirteString(text_input.getText().toString());
} catch (RemoteException e) {
Log.e(TAG, "Remote Exception while writing value to device.");
}
}
});
btn_read.setonClickListener(new View.onClickListener() {
@Override
public void onClick(View v) {
try{
text_result.setText(helloService.readString());
} catch (RemoteException e) {
Log.e(TAG, "Remote Exception while writing value to device.");
}
}
});
}
}
修改activity_main.xml
将AndroidStudioProjectsHelloappsrcmain目录下的所有文件和文件夹打包,并移动到虚拟机中aosp10/packages/apps目录下新建的Hello文件夹去
在aosp10/packages/apps/Hello目录下新建Android.mk文件
Android.mk
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := Hello LOCAL_DEX_PREOPT := false LOCAL_JACK_ENABLED := disabled LOCAL_PRIVATE_PLATFORM_APIS := true include $(BUILD_PACKAGE)编译Hello.apk
cd ~/documents/aosp10 export TARGET_PREBUILT_KERNEL=/home/test/documents/msm/arch/arm64/boot/Image.lz4-dtb source build/envsetup.sh lunch aosp_walleye-userdebug cd packages/apps/Hello/ mm
删掉这两个文件(packages/apps/Hello/res/values/themes.xml、packages/apps/Hello/res/values-night/themes.xml),重新编译
mm
报错
修改AndroidManifest.xml,删掉
android:theme="@style/Theme.Hello"
修改前
修改后
重新编译
mm编译完整镜像并重新刷机
编译,继续使用刚刚的terminal,先重新打包system.img
cd ../../.. make snod
重新编译
time make -j16
报错
解决
make api-stubs-docs-update-current-api time make -j16
报错
解决
make system-api-stubs-docs-update-current-api time make -j16
刷机
sudo su source build/envsetup.sh lunch aosp_walleye-userdebug adb shell reboot bootloader cd out/target/product/walleye/ fastboot flashall -w
测试
本文涉及到的知识主要和Android架构中的应用程序层、应用程序框架层相关
参考Android应用程序访问linux驱动第四步:实现android应用程序_阳光玻璃杯-CSDN博客



