Class androidx.browser.customtabs.CustomTabsIntent does not exist?

Sorry to be so annoying, but my project isn’t compiling. The reason is that “package androidx.browser.customtabs does not exist”. However, it is right in the Google Developers documentation!

Just to be sure, I enabled AndroidX support.

My code:

package com.gordonlu.customtabs;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import java.lang.Object;
import androidx.appcompat.app.AppCompatActivity;

import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;

@DesignerComponent(
        version = 1,
        description = "A non-visible component that opens web pages as custom tabs on Google Chrome.",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class CustomTabs extends AndroidNonvisibleComponent{

    //Activity and Context
    private Context context;
    private Activity activity;
    public String url = "https://www.google.com";
    public int col = -16711936;

    public CustomTabs(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR,
      description = "The URL to load in the custom tab. The URL must start with 'http://' or 'https://'.")
    public String URL() {
        return url;
    }

    @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING,
      defaultValue = "https://appinventor.mit.edu/")
    @SimpleProperty
    public void URL(String url) {
        this.url = url;
    }

    @SimpleProperty(category = PropertyCategory.BEHAVIOR,
      description = "Specifies the color of the toolbar.")
    public int ToolbarColor() {
        return col;
    }

    @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_INTEGER,
      defaultValue = "-16711936")
    @SimpleProperty
    public void ToolbarColor(int argb) {
        this.col = col;
    }

    @SimpleFunction(description = "Use this block to open the custom tab.")
    public void OpenCustomTab() {
        CustomTabsIntent.Builder customIntent = new CustomTabsIntent.Builder();
        customIntent.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.purple_200));
        openCustomTab(MainActivity.this, customIntent.build(), Uri.parse(url));
    }

    public static void OpenCustomTabOpenPage(Activity activity, CustomTabsIntent customTabsIntent, Uri uri) {
        String packageName = "com.android.chrome";
        activity.startActivity(new Intent(Intent.ACTION_VIEW, uri));
    }
}

Error message:

Started Compiling Project CustomTabs
Buildfile: /compiler/androidX/build.xml

javac:
[mkdir] Created dir: /compiler/androidX/build/HoWSX/classes
[javac] Compiling 1 source file to /compiler/androidX/build/HoWSX/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/androidX/build/HoWSX/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/androidX/build/HoWSX/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/androidX/build/HoWSX/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/androidX/build/HoWSX/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/androidX/build/HoWSX/classes/ComponentsTranslation.java
[javac] /compiler/androidX/src/HoWSX/com/gordonlu/customtabs/CustomTabs.java:22: error: package androidx.browser.customtabs does not exist
[javac] import androidx.browser.customtabs.CustomTabsIntent;
[javac] ^
[javac] /compiler/androidX/src/HoWSX/com/gordonlu/customtabs/CustomTabs.java:89: error: cannot find symbol
[javac] public static void OpenCustomTabOpenPage(Activity activity, CustomTabsIntent customTabsIntent, Uri uri) {
[javac] ^
[javac] symbol: class CustomTabsIntent
[javac] location: class CustomTabs
[javac] 2 errors

What is the name of your project?
is your project name and class name the same?

It’s an easy-to-fix issue. It is due to some time Niotron doesn’t save the latest update what we do in the project.

For example: you added a component you are seeing in niotron web but when you try to build it it will be missing for niotron backend server.

This issue is most common in google chrome.

FIx is just clear cache of your browser and then add the component again

No, they are different.

I cleared the browser cache and compiled it again, but still the compilation failed.

Make both same and try again

I made them the same, still failed.

@Gordon_Lu I need permission from you to copy your code and can i try compiling it in Rush made by @Shreyash

Ok sure, you can.