0

i'm curious how static methods: d, vv,etc methods works in Android. I have opened the source code and so that the only thing the methods d,v,etc do is to call to static println method, but this function does nothing. Attached println method code from Log.class file:

 public static int println(int priority, String tag, String msg) {
    return println(LOG_ID_MAIN, priority, tag, msg);
}

/** @hide */ public static final int LOG_ID_MAIN = 0;
/** @hide */ public static final int LOG_ID_RADIO = 1;
/** @hide */ public static final int LOG_ID_EVENTS = 2;
/** @hide */ public static final int LOG_ID_SYSTEM = 3;
/** @hide */ public static final int LOG_ID_CRASH = 4;

/** @hide */ @SuppressWarnings("unused")
public static int println(int bufID,
        int priority, String tag, String msg) {
    return 0;
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Eitanos30
  • 1,331
  • 11
  • 19

1 Answers1

0

I'm sure you don't correlate the source code correctly. If you correlate the source code correctly, you should see the same code like the picture below.

enter image description here

You can see how the println_native method is implemented online.

https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/util/Log.java

https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android_util_Log.cpp


I uploaded the way the java method is associated with the native method. For a description of JNI, you can refer here.

enter image description here

Teffy
  • 51
  • 6
  • whene i follow the println method (inside package android.util.Log) call form d method, it sent me to the code i have posted. Does this method belongs to different class? Can you explain me why it takes me to that code and not to the code you have posted? In addition i follow the link you have sent me and see that println_native only have signature, without implementation – Eitanos30 Dec 08 '19 at 10:15
  • Can you give the full package name of your Log class? Generally, the Log class in the android.util.log package is used to print the log in android. The package name of the log class you imported may be wrong. – Teffy Dec 08 '19 at 13:52
  • The println_native method is a native method, which will link to the android_util_Log_println_native method in the [android_util_Log.cpp](https://android.googlesource.com/platform/frameworks/base/+/master/core/jni/android_util_Log.cpp) file of the native layer via jni – Teffy Dec 08 '19 at 14:03
  • The package name is: "package android.util;" Is it a way here so i will send you a screenshot or something else? Maybe i'm using an old source? i have no idea... – Eitanos30 Dec 08 '19 at 14:09
  • In the link you send for the native_println method in java, i only see the signature without any implementation, so how can i understand that there is a link to cpp file? should i see any "witness"? – Eitanos30 Dec 08 '19 at 14:12
  • Thanks. I think i understand your extensive explanation, but can you say why Android Studio keeps showing me the Log.java file differently from the way it appears in your screenshot ( What am i doing wrong) ? In addition how can i find the println_native src code that you displayed (second screenshot)? Is it part of the JDK? – Eitanos30 Dec 09 '19 at 11:00
  • What is your compileSdkVersion? – Teffy Dec 11 '19 at 03:49
  • And I checked the Log.java in android 2.3-9.0, the codes are all like this. I have no idea about why Android Studio show the wrong code. – Teffy Dec 11 '19 at 04:00
  • Is it possible that android-29? i found the number at platform folder: Android\SDK\Platforms – Eitanos30 Dec 11 '19 at 15:28
  • I was surprised that I changed my compileSdkVersion to 29 and I saw that the code is indeed the same as yours. But I check the [Log.java](https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-10.0.0_r20/core/java/android/util/Log.java) in the android 10.0 latest source code, and it still use the println_native method. Maybe the official Android SDK provider believes that ordinary app developers do not need to know the real implementation method. – Teffy Dec 12 '19 at 03:23
  • Thanks. Can you please explain, or attach a link to place where can I understand what is the difference between compile sdk version 29 (which is part of the Android development tool), and android 10 latest source code? I understand that api level and the Android internal source code are different things, but do they both have the same file name Log.java, or the Log.java is already belongs to Android10 and when clicking on the Log word in the Android studio it passes me to Android internal code Log.java . In other word, to who the Log.java file belongs to? – Eitanos30 Dec 12 '19 at 08:29
  • [Here](https://developer.android.com/studio/releases/platforms) is a description of the changes in each SDK version. It only describes the changes that developers need to pay attention to and how they are compatible. It does not detail the changes of each Java class. – Teffy Dec 13 '19 at 13:02
  • Thanks but unfortunately i couldn't still understand what happens for example in Log.java file. How is it possible that there are two implementation? does the android X (any platform number) implements class we are using when writing and compiling our code? i thought all the API's we are using exist only in the sdk – Eitanos30 Dec 13 '19 at 16:47