在依赖项模块中找不到活动文件



这是依赖模块中活动文件的路径:

app/src/main/dependencies/base/src_java/com/project
/test/base/BaseActivity.java

这是我的主要活动的途径:

appsrcmainjavacomkernelappexperimentExperimentActivity.java

在我的 ExperimentActivity.java 文件中,我尝试导入 TestActivity.java 文件,该文件属于测试模块,它是我的实验项目的依赖项。这是代码:

package com.kernel.app.experiment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import com.project.test.base.TestActivity;

public class ExperimentActivity extends TestActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}

这是我尝试导入的文件:

package com.project.test.base;
// imports are written here
import org.libsdl.app.SDLActivity;
public class TestActivity extends SDLActivity implements
MagnetSensor.OnCardboardTriggerListener, NfcSensor.OnCardboardNfcListener,
Choreographer.FrameCallback {
// more code ...
}

但是,我不断收到这些错误: 在我的 gradle 控制台中,我收到一条错误消息,内容如下:

Execution failed for task ':app:compileDebugJavaWithJavac'.

在我的消息 Gradle 构建中,我收到以下错误消息:

Error:(12, 30) error: package com.project.test.base does not exist
Error:(38, 40) error: cannot find symbol class TestActivity
Error:(39, 3) error: method does not override or implement a method from a supertype
Error:(41, 5) error: cannot find symbol variable super
Error:(42, 5) error: cannot find symbol method getWindow()
Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.

这是我的Android清单.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kernel.app.experiment">
<uses-feature android:glEsVersion="0x00020000"/>
<uses-feature android:glEsVersion="0x00030000"/>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="26"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ExperimentActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

这是我的模块build.gradle:

应用插件:"com.android.application">

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.kernel.app.experiment"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild{
// cppFlags "-std=c++11 -frtti -fexceptions"
arguments "APP_PLATFORM=android-19"
}
}
}
buildTypes {
debug{
ndk{
abiFilters "x86", "armeabi-v7a"
// abiFilters ABI_FILTERS
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk{
abiFilters "x86", "armeabi-v7a"
// abiFilters ABI_FILTERS
}
}
}
externalNativeBuild {
ndkBuild{
//path "CMakeLists.txt"
path "src/main/jni/Android.mk"
}
}
}
repositories {
flatDir {
dirs System.env.FIREBASE_SDK + '/libs/android'
}
}

configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs/android', include: ['*.aar'])
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-games:10.0.1'
implementation 'com.google.android.gms:play-services-nearby:10.0.1'
implementation 'com.google.firebase:firebase-ads:10.0.1'
implementation 'com.google.firebase:firebase-core:10.0.1'
implementation 'com.google.firebase:firebase-invites:10.0.1'
//compile 'com.google.firebase:firebase-messaging:10.0.1'
implementation 'com.google.firebase:firebase-config:10.0.1'
//compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
//implementation 'com.android.support:support-v4:23.0+'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

如何让构建系统找到导入此缺失包的正确途径?

我认为您必须使用以下方法将模块添加到项目中

1-文件>新建>导入模块

2-添加

apply plugin: 'MODULE_NAME'

在你的build.gradle中,所以它会

android {
compileSdkVersion 26
defaultConfig {
applicationId "com.kernel.app.experiment"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
ndkBuild{
// cppFlags "-std=c++11 -frtti -fexceptions"
arguments "APP_PLATFORM=android-19"
}
}
}
buildTypes {
debug{
ndk{
abiFilters "x86", "armeabi-v7a"
// abiFilters ABI_FILTERS
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk{
abiFilters "x86", "armeabi-v7a"
// abiFilters ABI_FILTERS
}
}
}
externalNativeBuild {
ndkBuild{
//path "CMakeLists.txt"
path "src/main/jni/Android.mk"
}
}
}
repositories {
flatDir {
dirs System.env.FIREBASE_SDK + '/libs/android'
}
}

configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs/android', include: ['*.aar'])
implementation 'com.google.android.gms:play-services-base:10.0.1'
implementation 'com.google.android.gms:play-services-games:10.0.1'
implementation 'com.google.android.gms:play-services-nearby:10.0.1'
implementation 'com.google.firebase:firebase-ads:10.0.1'
implementation 'com.google.firebase:firebase-core:10.0.1'
implementation 'com.google.firebase:firebase-invites:10.0.1'
//compile 'com.google.firebase:firebase-messaging:10.0.1'
implementation 'com.google.firebase:firebase-config:10.0.1'
//compile 'com.google.firebase.messaging.cpp:firebase_messaging_cpp@aar'
//implementation 'com.android.support:support-v4:23.0+'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'MODULE_NAME'

3- 和在设置中.gradle

include ':app', ':MODULE_NAME'

尝试将库导入 Android Studio

  1. 在 Android Studio 中打开您的项目。
  2. 下载依赖项模块(使用 Git 或 zip 存档解压缩(。
  3. 在项目目录中创建一个文件夹"testProject"。
  4. 将依赖项模块代码复制并粘贴到 testProject 文件夹中。
  5. 在项目目录的根目录上创建/修改 settings.gradle 文件。

    include 'MyApp', ':testProject:TestLibrary'

  6. Gradle Clean 并构建/关闭项目,然后重新打开/重新导入它。

  7. 编辑项目的 build.gradle 以将其添加到"论文"部分:

    dependencies { //... compile project(':subProject:FreemiumLibrary') }

  8. 公共类 ExperimentActivity 扩展了 TestActivity。

相关内容

  • 没有找到相关文章

最新更新