将 Nativescript 升级到 6 android.support.v4 后,项目无法编译

After upgrading Nativescript to 6 android.support.v4 is missing and project fails to compile

将 Nativescript 升级到 6 后 android.support.v4 库丢失,我的项目无法编译并抛出以下错误:

error TS2339: Property 'text' does not exist on type 'typeof v4'

error TS2339: Property 'widget' does not exist on type 'typeof v4'

这就是我正在做的事情:

android.support.v4.widget.TextViewCompat.setAutoSizeTextTypeWithDefaults((this.whatLabel.nativeElement as Label).android, android.support.v4.widget.TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

android.support.v4.text.BidiFormatter.getInstance(new java.util.Locale("iw")).unicodeWrap(text, android.support.v4.text.TextDirectionHeuristicsCompat.RTL)

我的 reference.d.ts 文件包含这一行:

<reference path="../node_modules/tns-platform-declarations/android-22.d.ts" />

也尝试过:

<reference path="../node_modules/tns-platform-declarations/android.d.ts" />

从 v6.0 开始不再支持库。

Migrating to v6.0 / AndroidX

NativeScript 6.0 supports the Android extension libraries (AndroidX). The Android Support Library is no longer supported. Any application and plugin code relying on the support library must start using AndroidX instead. To learn how to migrate, follow the dedicated blog post.

终于找到解决办法了。

let androidSupport=null;
let anyGlobal = global as any;
if (anyGlobal.androidx && anyGlobal.androidx.core)
{
    androidSupport = anyGlobal.androidx.core;
}
else if (android.support && android.support.v4) {
    androidSupport = android.support.v4;
}

androidSupport.widget.TextViewCompat.setAutoSizeTextTypeWithDefaults((this.whatLabel.nativeElement as Label).android, androidSupport.widget.TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);

androidSupport.text.BidiFormatter.getInstance(new java.util.Locale("iw")).unicodeWrap(text, androidSupport.text.TextDirectionHeuristicsCompat.RTL)

来源:http://fluentreports.com/blog/?p=720