Gradle构建:Cannot resolve external dependency com.android.support:multidex:1.0.0 because no repositories are defined

寒天 发布于 2015/01/13 15:33
阅读 11K+
收藏 0

使用Gradle构建Android项目失败了,能帮看看问题么

A problem occurred configuring project ':myDemo'.

> Could not resolve all dependencies for configuration ':myDemo:_myDemoDebugCompile'.
   > Cannot resolve external dependency com.android.support:multidex:1.0.0 because no repositories are defined.
     Required by:
         dev:myDemo:unspecified




* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.




BUILD FAILED




Total time: 19.22 secs

加载中
0
Feng_Yu
Feng_Yu
把build.gradle内容贴出来看看,这个意思说你少了依赖项
寒天
寒天
multiDexEnabled true 去掉这一行,就OK了,是没有多dex支持么,但是又提供了这个
0
寒天
寒天

引用来自“Feng_Yu”的评论

把build.gradle内容贴出来看看,这个意思说你少了依赖项
apply plugin: 'com.android.application'


dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':alipay_lib')
    compile project(':upomp_Res_v1_1')
}


task copyNativeLibs(type: Copy) {
    from(new File('libs')) { include '**/*.so' }
    into new File(buildDir, 'native-libs')
}


clean.dependsOn 'cleanCopyNativeLibs'


tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = [new File(buildDir, 'native-libs')]
}


android {
    compileSdkVersion 10
    buildToolsVersion "19.1.0"

defaultConfig {
versionCode 200
        versionName "2.0.0"
        minSdkVersion 8
        targetSdkVersion 19
        manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:"default_channel" ]
    }

dexOptions {  
        preDexLibraries = false  
    } 

lintOptions {
        abortOnError false
    }
    
    signingConfigs {
myConfig{
storeFile file("../../certificate/myDemo.keystore")
storePassword "myDemo"
keyAlias "myDemo.keystore"
keyPassword "myDemo"
}
}

//渠道Flavors
    productFlavors {
        myDemo {}
    }

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
 
    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:name ]
    }
 
    applicationVariants.all { variant ->
 
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
    
    buildTypes{
     release {
minifyEnabled true
zipAlignEnabled true
shrinkResources true
        proguardFiles 'proguard-project.txt'
        signingConfig  signingConfigs.myConfig
     } 
   }
   
productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:name ]
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }


        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')


        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

寒天
寒天
回复 @Feng_Yu : 好的,我看看
Feng_Yu
Feng_Yu
回复 @寒天 : 可以参考stackoverflow的帖子。http://stackoverflow.com/questions/24795079/error1-0-plugin-with-id-com-android-application-not-found 把maven仓库和依赖项加上再build就可以了。
Feng_Yu
Feng_Yu
回复 @寒天 : 你这个生成的build.gradle没有加入maven仓库,所以报错依赖项无法下载。你可以网上找个android的gradle构建模板手改,也可以试试android studio生成的gradle
寒天
寒天
回复 @Feng_Yu : 我项目是eclipse的,这个是生成的,有两个library的依赖库,buildscript的在外面,这个build.gradle是主工程的
Feng_Yu
Feng_Yu
你的build.gradle没贴全吧,我看了一下我的build.gradle模板,刚开始是有buildscript配置段的,里面有maven仓库和android依赖项.是你没复制全还是你的build.gradle就长这个样子?
下一页
0
寒天
寒天

引用来自“Feng_Yu”的评论

把build.gradle内容贴出来看看,这个意思说你少了依赖项

你好,如果在build.gradle 中指定了lib的话,是不是就不用build path了,这个是银联的library

 UNEXPECTED TOP-LEVEL EXCEPTION:
 java.lang.IllegalArgumentException: already added: Lcom/unionpay/upomp/lthj/plugin/ui/BuildConfig;
         at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
         at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
         at com.android.dx.command.dexer.Main.processClass(Main.java:685)
         at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
         at com.android.dx.command.dexer.Main.access$600(Main.java:78)
         at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
         at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
         at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
         at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
         at com.android.dx.command.dexer.Main.processOne(Main.java:596)
         at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
         at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
         at com.android.dx.command.dexer.Main.run(Main.java:230)
         at com.android.dx.command.dexer.Main.main(Main.java:199)
         at com.android.dx.command.Main.main(Main.java:103)
 warning: Ignoring InnerClasses attribute for an anonymous inner class

0
寒天
寒天

引用来自“Feng_Yu”的评论

把build.gradle内容贴出来看看,这个意思说你少了依赖项
apply plugin: 'com.android.application'


dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':alipay_lib')
    compile project(':upomp_Res_v1_1')
}


task copyNativeLibs(type: Copy) {
    from(new File('libs')) { include '**/*.so' }
    into new File(buildDir, 'native-libs')
}


clean.dependsOn 'cleanCopyNativeLibs'


tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = [new File(buildDir, 'native-libs')]
}


android {
    compileSdkVersion 10
    buildToolsVersion "19.1.0"

defaultConfig {
versionCode 200
        versionName "2.0.0"
        minSdkVersion 8
        targetSdkVersion 19
        manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:"default_channel" ]
    }

dexOptions {  
        preDexLibraries = false  
    } 

lintOptions {
        abortOnError false
    }
    
    signingConfigs {
myConfig{
storeFile file("../../certificate/myDemo.keystore")
storePassword "myDemo"
keyAlias "myDemo.keystore"
keyPassword "myDemo"
}
}

//渠道Flavors
    productFlavors {
        myDemo {}
    }

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
 
    productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:name ]
    }
 
    applicationVariants.all { variant ->
 
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")
                output.outputFile = new File(outputFile.parent, fileName)
            }
        }
    }
    
    buildTypes{
     release {
minifyEnabled true
zipAlignEnabled true
shrinkResources true
        proguardFiles 'proguard-project.txt'
        signingConfig  signingConfigs.myConfig
     } 
   }
   
productFlavors.all { flavor ->
        flavor.manifestPlaceholders = [ JPUSH_CHANNEL_VALUE:name ]
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }


        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')


        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

引用来自“寒天”的评论

我看博客,有说新版的要这样写,还一个问题,我自己的混淆脚本中,还需要加 -libraryjars libs/**.jar么,加了后报下面的错误,刚开始接触gradle,之前一直用ant的,麻烦你了,
* What went wrong:
Execution failed for task ':myDeom:proguardmyDeomRelease'.
> java.io.IOException: The same input jar [E:\myDeom_project\dev\myDeom\libs\pinyin4j-2.5.0.jar] is specified twice.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
0
寒天
寒天

引用来自“Feng_Yu”的评论

把build.gradle内容贴出来看看,这个意思说你少了依赖项
回复 @Feng_Yu : 嗯,还一个问题,


:myDeom:proguardmyDeomRelease FAILED


FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':myDeom:proguardmyDeomRelease'.
> Java heap space


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
一直报堆空间的错误,我在gradlew中也加了
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\" \"-Xmx1024m\" \"-Xms256m\" \"-XX:MaxPermSize=1024m\""
麻烦你了,不好意思
寒天
寒天
回复 @Feng_Yu : 好的,我去看下
Feng_Yu
Feng_Yu
回复 @寒天 : 试试把eclipse的JVM参数拷贝进去。不过gradle是可以在build的时候指定java_opts的,可以google(build.gradle java_opts)看官方文档,我这边没遇到过这样的问题,JVM默参编译都是可以过的。gradle兼容ant,可以轻松的从ant迁移到gralde。gradle支持maven这个很赞,不需要在项目下放一堆jar包占版本库容量了
寒天
寒天
回复 @Feng_Yu : 只是打包,eclipse打包是OK的,之前一直用的ant,因为ant对library的支持不好,就放弃了
Feng_Yu
Feng_Yu
这个脚本会从系统环境变量中读取JAVA_OPTS配置。也可以export JAVA_OPTS这种方式直接写入环境变量中。反复Java heap space就需要检查你的代码了,也许是优化做的有问题,况且permsize不需要太大,默认的一般都是够的
返回顶部
顶部