简体   繁体   English

如何开发Android系统/平台应用程序

[英]How to develop Android System/Platform Apps

I'm working on a system application that is signed using the platform keys that I'm using to make my own ROM (from AOSP) but I have to do some workarounds in my code in order to use the platform classes and functions, when I try to use them directly Android Studio tells me that I'm trying to use a hidden API. 我正在使用我用来制作我自己的ROM(来自AOSP)的平台密钥进行签名的系统应用程序,但我必须在我的代码中做一些变通方法才能使用平台类和函数,我尝试直接使用它们Android Studio告诉我,我正在尝试使用隐藏的API。

I want to write code like the Settings, Launcher, framework. 我想编写像Settings,Launcher,框架这样的代码。 I know their source that is how I'm writing my own but I have to invoke classes using reflection, trying to do the way they are written not even builds on Android Studio. 我知道他们的来源是我自己编写的,但是我必须使用反射调用类,尝试按照Android Studio上的编写方式进行操作。

I don't want to use root commands to archive the functionality of my application that is why I'm doing this. 我不想使用root命令来存档我的应​​用程序的功能,这就是我这样做的原因。 The ROM I'm building will be installed without root access to the user (user build). 我正在构建的ROM将在没有root用户访问权限的情况下安装(用户构建)。

For example in Settings app, to enable MTP storage: 例如,在“设置”应用中,要启用MTP存储:

UsbManager mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);

But if I use that code in Android Studio, It is not even recognized as valid: 但是如果我在Android Studio中使用该代码,它甚至不被认为是有效的:

http://i.stack.imgur.com/R86OW.png (screenshot) http://i.stack.imgur.com/R86OW.png (截图)

I have to do this way in order to archive that (it currently works this way): 我必须这样做才能存档(它目前以这种方式工作):

UsbManager UsbManagerP = (UsbManager)getSystemService(Context.USB_SERVICE);
String setCurrentFunctionMethodName = "setCurrentFunction";
Method setCurrentFunctionMethod = null;
try {
    setCurrentFunctionMethod = UsbManagerP.getClass().getMethod(setCurrentFunctionMethodName, String.class, boolean.class);
    setCurrentFunctionMethod.invoke(UsbManagerP, "mtp",true);
    Log.d("OBS", "MTP ACTIVO");
} catch (NoSuchMethodException e) {
    Log.d("OBS", "Error No Existe Metodo");
} catch (InvocationTargetException e) {
    Log.d("OBS", "Error No Existe Objetivo");
} catch (IllegalAccessException e) {
    Log.d("OBS", "Error No Se puede acceder al metodo (illegal access)");
}

I really need help, maybe someone that has previously worked for Samsung/Sony/Motorola, etc. and share some knowledge about creating system apps. 我真的需要帮助,可能是之前曾在三星/索尼/摩托罗拉等公司工作的人,并分享了一些有关创建系统应用程序的知识。

As your application will be included in the ROM (and should be installed in /system + signed with the platform key) it would probably be simpler to compile the application in the AOSP source tree itself. 由于您的应用程序将包含在ROM中(并且应该使用平台密钥安装在/ system + signed中),因此在AOSP源代码树本身中编译应用程序可能更简单。

Doing this is pretty simple: 这样做非常简单:

  • Copy the sources of your app into '$BUILD_ROOT/packages/apps/' (or add a reference to it into your own local_manifest to have 'repo sync' handle it) 将您的应用程序的源复制到'$ BUILD_ROOT / packages / apps /'(或将其引用添加到您自己的local_manifest中以使'repo sync'处理它)
  • Add an Android.mk file to your application. 将Android.mk文件添加到您的应用程序。 An example can be found here: https://github.com/adrian-bl/android_jpolly 可以在这里找到一个例子: https//github.com/adrian-bl/android_jpolly
  • Include the name of your app (Android.mk: LOCAL_PACKAGE_NAME) into your build $PRODUCT_PACKAGES (eg: device.mk -> PRODUCT_PACKAGES += UsbWhatever) 将您应用的名称(Android.mk:LOCAL_PACKAGE_NAME)包含在您的构建$ PRODUCT_PACKAGES中(例如:device.mk - > PRODUCT_PACKAGES + = UsbWhatever)

That's it: The Android build system will now automatically build your app as part of the normal build process, giving you access to all system features. 就是这样:Android构建系统现在将自动构建您的应用程序,作为正常构建过程的一部分,使您可以访问所有系统功能。 The app will also automatically be stored in /system + signed with the platform key. 该应用程序还将自动存储在/ system +使用平台密钥签名。

Note that you can do incremental builds of your app by running 'mm'. 请注意,您可以通过运行'mm'来执行应用的增量构建。

Example: 例:

$ . build/envsetup.sh
$ lunch <your device config>
$ cd packages/app/UsbWhatever
$ mm  # <-- this will rebuild your package

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM