Почему я не могу вызвать метод create объекта FakeSplitInstallManagerFactory, который требует только передачи контекста? - PullRequest
0 голосов
/ 24 февраля 2020

Новый FakeSplitInstallManagerFactory имеет метод create, который принимает Context, однако, когда я пытаюсь использовать его из своего кода, я получаю только метод, который принимает Context и File, который является каталогом. Если я скажу AS показать мне определение класса, я смогу увидеть оба create метода. Они оба public и оба static, но из моего кода можно вызвать только одну. Я попытался очистить, снова запустить Gradle, и т. Д. c. Я не понимаю, в чем проблема?

Это ошибка, которую я получаю:

enter image description here

Это то, что я получаю при автозаполнении:

enter image description here

Если я нажимаю control+b, я получаю:

package com.google.android.play.core.splitinstall.testing;

import com.google.android.play.core.splitcompat.SplitCompat;
import com.google.android.play.core.splitinstall.SplitInstallManager;
import android.content.Context;

/** Creates instances of {@link com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager FakeSplitInstallManager}. */

@SuppressWarnings({"unchecked", "deprecation", "all"})
public class FakeSplitInstallManagerFactory {

public FakeSplitInstallManagerFactory() { throw new RuntimeException("Stub!"); }

/**
 * Creates a fake implementation of the {@link com.google.android.play.core.splitinstall.SplitInstallManager SplitInstallManager}.
 *
 * <p>This implementation is self-contained and obtains splits from a specified directory, which
 * can be populated passing the --local-testing flag to bundletool build-apks and using bundletool
 * install-apks to install the app.
 *
 * <p>It is provided for testing, e.g. checking sequences of events when installing dynamic
 * features and additional languages. It is suitable for use in integration tests.
 *
 * <p>This fake supports just one install request at a time.
 *
 * <p>Network errors can be simulated using {@link com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager#setShouldNetworkError(boolean) FakeSplitInstallManager#setShouldNetworkError(boolean)}.
 *
 * <p>{@link com.google.android.play.core.splitcompat.SplitCompat SplitCompat} must be installed appropriately to use this class.
 *
 * <p>This method will always return the same {@link com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager FakeSplitInstallManager} instance.
 */

public static com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager create(android.content.Context context) { throw new RuntimeException("Stub!"); }

/**
 * Alternative version of {@link #create(android.content.Context)} which allows for the splits directory to be set
 * explicitly.
 *
 * <p>The constructor receives the directory on the device where the split apks can be obtained.
 * The file name format is the same as the extracted output of bundletool build-apks. The apks in
 * the directory must be signed by the same certificate as the app. If this directory is missing,
 * install requests will fail with {@link
 * com.google.android.play.core.splitinstall.model.SplitInstallErrorCode#API_NOT_AVAILABLE}.
 *
 * <p>In general, all configuration splits for the module that are present in the folder will be
 * included. Thus, consider pre-filtering them for the device - e.g. using appropriate bundletool
 * build-apks argument. However, since languages can change over time on the device, there will be
 * additional filtering of language splits, whereby only appropriate languages will be included.
 *
 * <p>Prefer using {@link #create(android.content.Context)} and let bundletool populate the default directory,
 * unless there's a good reason to use a different directory or filter the delivered APKs by hand.
 *
 * <p>This method will always return the same {@link com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager FakeSplitInstallManager} instance. It will
 * fail if called twice with different directories.
 */

public static synchronized com.google.android.play.core.splitinstall.testing.FakeSplitInstallManager create(android.content.Context context, java.io.File modulesDirectory) { throw new RuntimeException("Stub!"); }
}

Что ясно показывает два create методы.

Я использую библиотеку play core 1.6.5, и это новый чистый проект, в котором больше ничего нет. Прямо сейчас я создал новый чистый проект из шаблона, затем добавил implementation "com.google.android.play:core:1.6.5", и у него точно такая же проблема. Так что я делаю не так?

Спасибо.

1 Ответ

1 голос
/ 25 февраля 2020

Я знаю, что это странно, но когда вы проверяете FakeSplitInstallManagerFactory.class из com.google.android.play:core AAR, по какой-то причине, похоже, что они его пропустили? Вот почему он не позволит вам использовать create(context).

public class FakeSplitInstallManagerFactory {
    private static FakeSplitInstallManager a = null;

    public FakeSplitInstallManagerFactory() {
    }

    public static synchronized FakeSplitInstallManager create(Context var0, File var1) {
        if (a == null) {
            try {
                a = new FakeSplitInstallManager(var0, var1);
            } catch (Exception var3) {
                throw new RuntimeException(var3);
            }
        } else if (!a.a().getAbsolutePath().equals(var1.getAbsolutePath())) {
            throw new RuntimeException(String.format("Different module directories used to initialize FakeSplitInstallManager: '%s' and '%s'", a.a().getAbsolutePath(), var1.getAbsolutePath()));
        }

        return a;
    }
}

Может быть, они добавят его позже, так как документы, Локальный тестовый модуль устанавливают: Имитирует ошибку сети упоминает отсутствующий метод (или, может быть, они устарели в пользу create(context, file), но просто не обновили документы), посмотрим ...

Но вот недавний medium / Простой способ проверить автономную динамику c доставку , в которой рассказывается, как использовать create(context, file)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...