生成apk后未找到Java静态接口方法

生成apk后未找到Java静态接口方法,java,android,Java,Android,我怀疑在接口上使用静态方法 在我的项目中,有一个应用程序模块和两个android lib模块 它们的依赖关系:app->engine->library 在「图书馆」模块中,一段代码如下: public interface Base { void test(); static Base create(){ return new BaseImpl(); } } public class BaseImpl implements Base { @Ov

我怀疑在接口上使用静态方法

在我的项目中,有一个应用程序模块和两个android lib模块

它们的依赖关系:
app->engine->library

在「图书馆」模块中,一段代码如下:

public interface Base {

    void test();

    static Base create(){
        return new BaseImpl();
    }
}

public class BaseImpl implements Base {
    @Override
    public void test() {
        System.out.println("Library Base test");
    }
}
在「引擎」模块中

public class Engine {

    public static void init(){
        Base.create().test();
    }
}
在应用中

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Engine.init();
            }
        });
    }
}
应用程序模块
build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

}


repositories {
    flatDir {
        dirs 'libs'   // aar dir
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

   // implementation project(':engine')
    implementation name: "engine-release", ext: "aar"   //「engine」 lib aar
    implementation name: "library-release", ext: "aar"  //「library」 lib aar
}
我将「引擎」和「图书馆」交给aar。并将它们添加到应用程序的依赖项中

使用Android Studio
构建->构建Apk
构建Apk。生成过程不报告任何错误

但我安装了apk并运行了应用程序,它会出错:

java.lang.NoSuchMethodError: No static method create()Lcom/example/library/Base; in class Lcom/example/library/Base; or its super classes (declaration of 'com.example.library.Base' appears in /data/app/com.example.test-Ppe6YDrBRQEbvwbWKx0Ppg==/base.apk)
我反编译了apk文件,发现:

public interface Base {
    void test();

    /* renamed from: com.example.library.Base$-CC  reason: invalid class name */
    public final /* synthetic */ class CC {
        public static Base create() {
            return new BaseImpl();
        }
    }
}

public class Engine {
    public static void init() {
        Base.create().test();
    }
}
我不知道这种情况下会发生什么


示例来源:

您可以启用multiDex,因为您的min SDK版本低于21(棒棒糖)