android studio - gradle manifest file path

2019-08-21 02:47发布

问题:

I was trying to add the v4 support library in Android Studio.

My build.gradle lookes like this so far :

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
  }
}

allprojects {

  apply plugin: 'android'

  android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"        
  }

  repositories {
    mavenCentral()
  }

  dependencies {
    compile 'com.android.support:support-v4:18.0.+'
  }
}

It started giving me the error (my project name is DataSharing-1):

AndroidStudioProjects/DataSharing-1/src/main/AndroidManifest.xml (No such file or directory)

I tried adding the following under 'android {' :

sourceSets {
        main {
            manifest.srcFile 'DataSharing-1/app/src/main/AndroidManifest.xml'
        }
    }

I get the error :

DataSharing-1/app/app/src/main/AndroidManifest.xml (No such file or directory)

If I change the srcFile to

'src/main/AndroidManifest.xml'

I get the error :

DataSharing-1/src/main/AndroidManifest.xml (No such file or directory)

My folder structure is :

AndroidStudioProjects/DataSharing-1/app/src/main/AndroidManifest.xml

Can someone suggest on how to resolve this problem ?

回答1:

The best way to add the support library to your project:

  1. Open build.gradle (the one with the android and dependencies element).
  2. Under dependencies add compile 'com.android.support:support-v4:+'

It should look as follows:

dependencies {
    compile 'com.android.support:support-v4:+'
    //... your previous existing dependencies after here
}

You can replace the + symbol with a specific version, but the + symbol is preferable since it ensures you will get the latest version of the library.