Android Studio: Gradle sync failed: Project: application declares dependency

I work in Android Studio 2.3 and I want to use the library I found in github ( https://github.com/henrychuangtw/Android-ChatHead ) and there is no Jar file. In settings.gradle, I declared the directory where the library is located:

include ':app' include ':Android-ChatHead' project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads') 

And I also added the library to the build.gradle dependencies:

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile project(':Android-ChatHead') 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.1.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' } 

After that, if I synchronize, I get this error:

Gradle Sync error: Project: the application declares a dependency on the 'compile' configuration for the 'default' configuration, which is not declared in the project descriptor: Android-ChatHead. Consult IDE Magazine for more information (Help | Show Log)

If I add / app at the end of the file path in settings.gradle, I get the following error:

 Error:Dependency Doritest:Android-ChatHead:unspecified on project core resolves to an APK archive which is not supported as a compilation dependency. File: /Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads/Android-ChatHead/app/build/outputs/apk/Android-ChatHead-release-unsigned.apk 

I can’t understand what I should do.

+5
source share
2 answers

You cannot add dependencies as far as I know. I assume that there is no dependency on the dependency you want to use, so you need to add Android-ChatHead as a module

To do this, follow these steps:

  • Choose File> New> Import Module.
  • In the "Source directory" field, enter or select the directory of the modules (modules) that you want to import:

    • If you are importing a single module, specify its root directory.

    • If you are importing multiple modules from a project, specify the project folder. For each module, a field appears inside the folder and indicates the source location and module name. Make sure the import check box is selected for each module that you want to import.

  • Enter the desired name of the module (s) in the field (s) of the module.

  • Click Finish.

  • In your .gradle settings add

    include ':app', ':Android-ChatHead'

  • In the dependencies section of your application build.gradle add

    compile project(':Android-ChatHead')

  • clear / create project

+2
source

Import by copy and by link is different

What P. Lorand does is referring to the module, not copying, so any changes that he makes to the module affect all other applications that refer to the module.

Using the method of Ivan Milisavlevich, the module is copied to the application. Editing an imported module is only valid in the application, sometimes a good idea, sometimes annoyance.

Application and module have different structure

The application has the root of the application and the application module inside it, commonly called the application.
The root module is the module itself.

changing this:

 project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads') 

to

 project(':Android-ChatHead').projectDir=new File('/Users/lorand/AndroidStudioProjects/Doritest/android_chatHeads/moduleName') 

may I help.

Also, if you are converting an application into a module, be sure to rename the app , two modules with the same app name are a promise of disaster.

With Android ChatHead

It contains the application folder, therefore it is an application, not a module.
build.gradle contains the line apply plugin: 'com.android.application' , so the application bit must be replaced with library .
Comment applicationId "henrychuang.tw.chatheadmsg" .
Rename the module name application to another; I never did this manually, with the android studio ctl + alt + r on the Application tab on the Project tab.

Then everything will be fine. First try to import a copy.

+1
source

Source: https://habr.com/ru/post/1266683/


All Articles