From e2dc33a663c242053b450960c969a70978b0555a Mon Sep 17 00:00:00 2001 From: Kyant0 Date: Mon, 2 Dec 2024 23:21:26 +0800 Subject: [PATCH] Remove androidx.annotation to fix duplicate class issue --- .../java/androidx/annotation/NonNull.java | 34 --------------- .../java/androidx/annotation/Nullable.java | 41 ------------------- .../main/java/com/kyant/fishnet/Fishnet.java | 7 +++- .../kyant/fishnet/JavaExceptionHandler.java | 20 +++++---- .../kyant/fishnet/NativeSignalHandler.java | 16 ++++---- gradle/libs.versions.toml | 2 +- 6 files changed, 24 insertions(+), 96 deletions(-) delete mode 100644 fishnet/src/main/java/androidx/annotation/NonNull.java delete mode 100644 fishnet/src/main/java/androidx/annotation/Nullable.java diff --git a/fishnet/src/main/java/androidx/annotation/NonNull.java b/fishnet/src/main/java/androidx/annotation/NonNull.java deleted file mode 100644 index 3104bd9..0000000 --- a/fishnet/src/main/java/androidx/annotation/NonNull.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.annotation; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.CLASS; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Denotes that a parameter, field or method return value can never be null. - *

- * This is a marker annotation and it has no specific attributes. - */ -@Retention(CLASS) -@Target({METHOD, PARAMETER, FIELD}) -public @interface NonNull { -} diff --git a/fishnet/src/main/java/androidx/annotation/Nullable.java b/fishnet/src/main/java/androidx/annotation/Nullable.java deleted file mode 100644 index ee6544e..0000000 --- a/fishnet/src/main/java/androidx/annotation/Nullable.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package androidx.annotation; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.CLASS; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Denotes that a parameter, field or method return value can be null. - *

- * When decorating a method call parameter, this denotes that the parameter can - * legitimately be null and the method will gracefully deal with it. Typically - * used on optional parameters. - *

- * When decorating a method, this denotes the method might legitimately return - * null. - *

- * This is a marker annotation and it has no specific attributes. - */ -@Retention(CLASS) -@Target({METHOD, PARAMETER, FIELD}) -public @interface Nullable { -} diff --git a/fishnet/src/main/java/com/kyant/fishnet/Fishnet.java b/fishnet/src/main/java/com/kyant/fishnet/Fishnet.java index 11e10f2..54ae9f9 100644 --- a/fishnet/src/main/java/com/kyant/fishnet/Fishnet.java +++ b/fishnet/src/main/java/com/kyant/fishnet/Fishnet.java @@ -2,7 +2,7 @@ import android.content.Context; -import androidx.annotation.NonNull; +import java.util.Objects; /** * Fishnet is an Android library that dumps Java and native crashes. @@ -19,7 +19,10 @@ private Fishnet() { * @param context Application context * @param path Absolute path to store crash logs */ - public static void init(@NonNull Context context, @NonNull String path) { + public static void init(Context context, String path) { + Objects.requireNonNull(context, "context must not be null"); + Objects.requireNonNull(path, "path must not be null"); + NativeSignalHandler.init(context, path); JavaExceptionHandler.init(); } diff --git a/fishnet/src/main/java/com/kyant/fishnet/JavaExceptionHandler.java b/fishnet/src/main/java/com/kyant/fishnet/JavaExceptionHandler.java index 8765ff3..c060be9 100644 --- a/fishnet/src/main/java/com/kyant/fishnet/JavaExceptionHandler.java +++ b/fishnet/src/main/java/com/kyant/fishnet/JavaExceptionHandler.java @@ -1,7 +1,5 @@ package com.kyant.fishnet; -import androidx.annotation.NonNull; - import java.util.Map; final class JavaExceptionHandler { @@ -32,8 +30,7 @@ public static void init() { Thread.setDefaultUncaughtExceptionHandler(handler); } - @NonNull - private static String getStackTraceString(@NonNull StackTraceElement[] stackTrace) { + private static String getStackTraceString(StackTraceElement[] stackTrace) { StringBuilder sb = new StringBuilder(128); for (StackTraceElement element : stackTrace) { sb.append("at ").append(element).append("\n "); @@ -41,8 +38,7 @@ private static String getStackTraceString(@NonNull StackTraceElement[] stackTrac return sb.toString(); } - @NonNull - private static String getAllStackTracesExcept(@NonNull Thread excludedThread) { + private static String getAllStackTracesExcept(Thread excludedThread) { StringBuilder sb = new StringBuilder(128); for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { Thread t = entry.getKey(); @@ -53,13 +49,16 @@ private static String getAllStackTracesExcept(@NonNull Thread excludedThread) { sb.append('\n'); } } + int len = sb.length(); + if (len > 0) { + sb.deleteCharAt(len - 1); + } return sb.toString(); } /** * @noinspection unused */ - @NonNull private static String dumpJavaThreads() { StringBuilder sb = new StringBuilder(1024); for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { @@ -69,11 +68,14 @@ private static String dumpJavaThreads() { sb.append(getStackTraceString(stackTrace)); sb.append('\n'); } + int len = sb.length(); + if (len > 0) { + sb.deleteCharAt(len - 1); + } return sb.toString(); } - @NonNull - private static String toLogString(@NonNull Thread t) { + private static String toLogString(Thread t) { return "\"" + t.getName() + "\" " + (t.isDaemon() ? "daemon " : "") + "prio=" + t.getPriority() + " id=" + t.getId() + "\n" + " java.lang.Thread.State=" + t.getState(); diff --git a/fishnet/src/main/java/com/kyant/fishnet/NativeSignalHandler.java b/fishnet/src/main/java/com/kyant/fishnet/NativeSignalHandler.java index c12e8be..57c0159 100644 --- a/fishnet/src/main/java/com/kyant/fishnet/NativeSignalHandler.java +++ b/fishnet/src/main/java/com/kyant/fishnet/NativeSignalHandler.java @@ -7,13 +7,11 @@ import android.content.pm.SigningInfo; import android.os.Build; -import androidx.annotation.NonNull; - final class NativeSignalHandler { private NativeSignalHandler() { } - static void init(@NonNull Context context, @NonNull String path) { + static void init(Context context, String path) { String packageName = context.getPackageName(); PackageInfo packageInfo; @@ -72,19 +70,19 @@ static void init(@NonNull Context context, @NonNull String path) { nativeInit(path, packageName, versionName, versionCode, cert); } - static void dumpJavaCrash(@NonNull String javaStackTraces) { + static void dumpJavaCrash(String javaStackTraces) { nativeDumpJavaCrash(javaStackTraces); } private static native void nativeInit( - @NonNull String path, - @NonNull String packageName, - @NonNull String versionName, + String path, + String packageName, + String versionName, long versionCode, - @NonNull String cert + String cert ); - private static native void nativeDumpJavaCrash(@NonNull String javaStackTraces); + private static native void nativeDumpJavaCrash(String javaStackTraces); static { System.loadLibrary("com.kyant.fishnet"); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index df0f124..c325d09 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ android-targetSdk = "35" android-buildToolsVersion = "35.0.0" android-ndkVersion = "28.0.12674087" android-versionCode = "1" -lib-version = "1.0.0-alpha02" +lib-version = "1.0.0-alpha03" agp = "8.9.0-alpha03" # https://androidstudio.googleblog.com kotlin = "2.1.0" # https://github.com/JetBrains/kotlin