Packages from library module not found in main module

◇◆丶佛笑我妖孽 提交于 2019-12-12 11:25:20

问题


I got a project which I imported from Eclipse to Android Studio. In Eclipse everything worked well.

It contains a main module (a project in Eclipse) which uses packages from a library module (library project in Eclipse). Since the migration did not went well, I have created a library module manually and just copied all the source code to the newly created module.

The problem is that the main module doesn't seem to find the packages from the library module and when I rebuild the project I get errors like "package bla bla does not exist".

Here is the main module gradle.build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        applicationId "com.pointer.mamagoose"
        minSdkVersion 9
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':linphoneclean')
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.google.android.gms:play-services:9.4.0'
    compile files('libs/firebase-client-android-2.5.0.jar')
    compile files('libs/apache-httpcomponents-httpclient.jar')
    compile files('libs/apache-httpcomponents-httpcore.jar')
    compile files('libs/android-support-v7-recyclerview.jar')
}

linphoneclean is the library module.

The entire project's settings.gradle:

include ':linphoneclean'
include ':tigris'

This is the build.gradle of the library module:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.google.code.gson:gson:2.6.2'
    compile files('libs/commons-lang3-3.4.jar')
    compile files('libs/linphone.jar')
    compile files('libs/firebase-client-android-2.5.0.jar')
}

The structure of the library module includes for example folder: src/main/com/pointer/linphone (and inside there are all the java files with a deceleration of package com.pointer.linphone, Yet I still get an error saying >"package com.pointer.linphone does not exist).

What am I doing wrong?


回答1:


After fighting with the same issue for hours here is what worked for me.

I've created a fresh project with blank activity, added a library module with a dummy class, defined the dependency. Verified that it works by importing the dummy class in the app. Then I copied all my relevant code from the real project.

My thinking is that it was probably issue with IDE's iml files, since starting from scratch and copying stuff over worked.




回答2:


See properly source file contains both java folder and res folder,add java files in java packages and res in res folder.Add Activity name in Manifest file see here ,add necessary libraries files in Gradle file.Clean and rebuild the project in the Android studio.

https://developer.android.com/guide/topics/manifest/manifest-element.html




回答3:


Maybe you can check if the library's AndroidManifest has defined the package correctly, like:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
          package="com.pointer.linphone">


来源:https://stackoverflow.com/questions/40482184/packages-from-library-module-not-found-in-main-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!