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

时间:2018-08-19 22:47:18

标签: android gradle groovy android-ndk dependencies

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

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

这是我主要活动的途径:

app\src\main\java\com\kernel\app\experiment\ExperimentActivity.java

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

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'.

在我的Messages Gradle Build中,我收到以下错误消息:

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.

这是我的AndroidManifest.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'

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

2 个答案:

答案 0 :(得分:0)

我认为您必须使用

将模块添加到项目中

1-file> new>导入模块

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-和在setting.gradle

include ':app', ':MODULE_NAME'

答案 1 :(得分:0)

尝试将库导入Android Studio

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

    include 'MyApp', ':testProject:TestLibrary'

  6. 逐步清理并构建/关闭项目,然后重新打开/重新导入它。

  7. 编辑项目的build.gradle,以将其添加到“依赖关系”部分:

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

  8. 公共类ExperimentActivity扩展了TestActivity。

  9. 构建