Search code examples
nativescriptandroid-support-librarynativescript-angular

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


After upgrading Nativescript to 6 android.support.v4 library is missing and my project fails to compile throwing the following errors:

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

and

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

And this is what I'm doing:

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)

My reference.d.ts file contains this line:

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

Tried also:

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

enter image description here


Solution

  • Finally found a solution.

    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)
    

    Source: http://fluentreports.com/blog/?p=720