文章目录
- 简述
- 文件的添加
简述
创建AOSP源码可编译一个简单apk的过程,代码子目录结构图如下所示
文件的添加
1.com.custom.test目录下创建TestActivity.java文件
用于简单的界面显示类
package com.custom.test;
import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.custom.test.R;
public class TestActivity extends Activity {
private static final String TAG = "TestActivity";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
2.布局文件activity_test.xml
显示出来的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/btn_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:textAllCaps="false" />
</LinearLayout>
3.values下的资源文件
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_name">custom_test</string>
</resources>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.custom.test">
<application
android:allowBackup="false"
android:label="@string/app_name"
android:usesCleartextTraffic="false">
<activity
android:name=".TestActivity"
android:excludeFromRecents="true"
android:theme="@style/Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
5.Android.bp文件
android_app {
name: "custom_test",
static_libs: [
"androidx.annotation_annotation",
],
srcs: [
"src/**/*.java"
],
platform_apis: true,
certificate: "platform",
}
通过编译可输出一个custom_test.apk的文件