'How to solve API Lint error in AOSP build?
I'm using AOSP source file.I have created new service in Android 9 & it was running. When I tried to reuse the same in Android 11, getting API Lint Error from auto generated file (out folder)
1. IHelloworldService.java:43: error: Methods calling system APIs should rethrow RemoteException
as RuntimeException
(but do not list it in the throws clause) [RethrowRemoteException]
2. IHelloworldService.java:15: error: Raw AIDL interfaces must not be exposed: Stub extends Binder [RawAidl]
3. IHelloworldService.java:10: error: Missing nullability on method asBinder
return [MissingNullability]
I unable to try what is emitted in the terminal, (method 1 is not possible, since autogenerated file; method 1 is not possible, since mentioned folder is not available ) Can anyone help me with how to solve this? stuck for long time
Solution 1:[1]
You may override the bp file.Then add/override metalava_framework_docs_args section.
metalava_framework_docs_args = "
"--api-lint-ignore-prefix replace_with_your_class_name_or_prefix "
Solution 2:[2]
First off looks you have an unhandled exception. Basically you're using a method that is marked as throwing an exception, but not handling that exception anywhere in your code.
The second one this might help: https://developer.android.com/guide/components/aidl
Without seeing your code, it's hard to give you more help on that.
Found this question trying to solve the 3rd one. Eventually I figured it out myself.
Any method argument it complains about, you have to modify it to include more information.
So if it complained foo(Context context) was missing nullability on context, you'd need to find it and modify it to either:
public void foo(@NonNull Context context)
or
public void foo(@Nullable Context context)
You choice would depend on if the method foo can handle context being null.
If it complained method foo() was missing nullability
then either change it to:
@Nullable
public void foo()
or
@NonNull
public void foo()
Depending on if it might return null.
Solution 3:[3]
Because it is system APIs, so you need add /** @hide */ comment, can solve this, like this
package android.service.cfm880;
/** @hide */
interface IHelloService{
void hello(in String name);
}
current newest aosp master branch can work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Solskjaer49 |
Solution 2 | netsplit |
Solution 3 | Fangming Cheng |