访问非SDK接口上的隐藏方法logcat警告和限制

时间:2018-10-07 15:46:36

标签: java android android-9.0-pie

我已经在Android文档中阅读了有关“非SDK接口的限制”的内容:

  

只要应用引用非SDK,就会应用这些限制   接口或尝试使用反射或JNI获取其句柄...   非SDK接口的处理是一个实现细节,   API抽象了;它可随时更改,恕不另行通知...   列入灰色名单的非SDK接口包含方法和字段   继续在Android 9中运行,但我们不能保证   在平台的未来版本中访问...您可以使用adb logcat来   访问这些日志消息,这些消息显示在正在运行的PID下   应用...

以下是在API 28仿真器上运行的代码的相关部分:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 

           ................       

    MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");

           ................

    adView = new AdView(this);

    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    adView.setAdSize(AdSize.BANNER);
    adView.setBackgroundColor(Color.TRANSPARENT);
    adView.setVisibility(View.GONE);            
    adView.loadAd(adBuilder());

           ................

    interstitial = new InterstitialAd(GLGame.this);            
    interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    interstitial.loadAd(adBuilder());        

    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
    mRewardedVideoAd.setRewardedVideoAdListener(this);        
    loadRewardedVideoAd();        
}

AdRequest adBuilder() {
    return new AdRequest.Builder().build();
}
public void loadRewardedVideoAd() {        
    mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917", new AdRequest.Builder().build());        
}

我发现与

MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
adView.loadAd(adBuilder());
interstitial.loadAd(adBuilder());

我的Logcat输出是:

W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)
W: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (light greylist, reflection)

如果我通过评论禁用

//MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
//adView.loadAd(adBuilder());
//interstitial.loadAd(adBuilder());

正在访问的隐藏日志猫消失了。

与我获得Logcat输出之前相同:

W: Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (light greylist, reflection)

如果我通过评论禁用

//loadRewardedVideoAd();

正在访问的隐藏日志猫消失了。

如您所见,代码:

MobileAds.initialize(this,  "ca-app-pub-3940256099942544~3347511713");
adView.loadAd(adBuilder());
interstitial.loadAd(adBuilder());
loadRewardedVideoAd();

导致了很多访问隐藏的logcat。

我的问题是:

  1. 这些是模拟器的问题吗?
  2. 我是否有可能使用NON-SDK接口(请参阅访问隐藏方法,浅灰色列表,反射) 会在平台的未来版本中破坏我的应用程序吗?
  3. 如何解决?

1 个答案:

答案 0 :(得分:0)

列入灰色名单的非SDK接口表示方法和字段在Android 9中继续起作用,但是Google不保证在以后的平台版本中可访问这些方法和字段。如果由于某种原因您无法实施灰名单API的替代策略,则可以提交错误以请求重新考虑该限制。​​

https://issuetracker.google.com/issues/new?component=328403&template=1027267