【问题标题】:After upgrading Nativescript to 6 android.support.v4 is missing and project fails to compile将 Nativescript 升级到 6 后,缺少 android.support.v4 并且项目无法编译
【发布时间】:2019-08-24 21:28:24
【问题描述】:

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

错误 TS2339:“typeof v4”类型上不存在属性“text”

错误 TS2339:“typeof v4”类型上不存在属性“widget”

这就是我正在做的:

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" />

【问题讨论】:

    标签: nativescript android-support-library nativescript-angular


    【解决方案1】:

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

    Migrating to v6.0 / AndroidX

    NativeScript 6.0 支持 Android 扩展库 (AndroidX)。不再支持 Android 支持库。任何依赖于支持库的应用程序和插件代码都必须开始使用 AndroidX。要了解如何迁移,请关注dedicated blog post

    【讨论】:

    • 这没有帮助
    【解决方案2】:

    终于找到了解决办法。

    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

    【讨论】:

    • global 类似于浏览器环境中的window,是访问全局变量的一种方式。这不能解决打字问题,并且在 AndroidX 上会失败。
    • 您能否提供访问支持库的正确方法?
    猜你喜欢
    • 2014-04-27
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2013-11-29
    相关资源
    最近更新 更多