1#!/bin/sh 2 3# Creates an apex stub in a subdirectory named after the package name. Edit the APEX_NAME variable 4# before running. 5 6APEX_NAME=com.android.yourpackagenamehere 7 8mkdir ${APEX_NAME} 9cd ${APEX_NAME} 10 11cat > Android.bp <<EOF 12// Copyright (C) 2020 The Android Open Source Project 13// 14// Licensed under the Apache License, Version 2.0 (the "License"); 15// you may not use this file except in compliance with the License. 16// You may obtain a copy of the License at 17// 18// http://www.apache.org/licenses/LICENSE-2.0 19// 20// Unless required by applicable law or agreed to in writing, software 21// distributed under the License is distributed on an "AS IS" BASIS, 22// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23// See the License for the specific language governing permissions and 24// limitations under the License. 25apex_key { 26 name: "${APEX_NAME}.key", 27 public_key: "${APEX_NAME}.avbpubkey", 28 private_key: "${APEX_NAME}.pem", 29} 30 31android_app_certificate { 32 name: "${APEX_NAME}.certificate", 33 certificate: "${APEX_NAME}", 34} 35 36apex { 37 name: "${APEX_NAME}", 38 manifest: "manifest.json", 39 file_contexts: ":apex.test-file_contexts", // Default, please edit, see go/android-apex-howto 40 key: "${APEX_NAME}.key", 41} 42EOF 43 44openssl genrsa -out ${APEX_NAME}.pem 4096 45avbtool extract_public_key --key ${APEX_NAME}.pem --output ${APEX_NAME}.avbpubkey 46 47cat > csr.conf <<EOF 48[req] 49default_bits = 4096 50distinguished_name = dn 51prompt = no 52 53[dn] 54C="US" 55ST="California" 56L="Mountain View" 57O="Android" 58OU="Android" 59emailAddress="android@android.com" 60CN="${APEX_NAME}" 61EOF 62 63openssl req -x509 -config csr.conf -newkey rsa:4096 -nodes -days 999999 -keyout key.pem -out ${APEX_NAME}.x509.pem 64rm csr.conf 65openssl pkcs8 -topk8 -inform PEM -outform DER -in key.pem -out ${APEX_NAME}.pk8 -nocrypt 66rm key.pem 67 68cat > manifest.json << EOF 69{ 70 "name": "${APEX_NAME}", 71 "version": 1 72} 73EOF 74