javascript

java

python

c#

android

c++

node.js

php

html

jquery

ios

reactjs

css

.net

git

ruby-on-rails

sql

c

ruby

string

无法合并Dex-Android Studio 3.0

当我在稳定频道中将Android Studio更新为3.0并运行该项目时,我开始收到以下错误消息。

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我尝试清理和重建项目,但是没有成功。 任何帮助将不胜感激。

项目级别build.gradle

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.google.gms:google-services:3.1.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
} 
allprojects {
repositories {
    jcenter()
    google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

应用程序级别build.gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "com.med.app"
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    resConfigs "auto"
    multiDexEnabled true

}
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.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'

//appcompat libraries
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'


//butterknife
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//picasso
compile 'com.squareup.picasso:picasso:2.5.2'

//material edittext
compile 'com.rengwuxian.materialedittext:library:2.1.4'

// Retrofit & OkHttp & and OkHttpInterceptor & gson
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'

// FirebaseUI for Firebase Auth
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
}
apply plugin: 'com.google.gms.google-services'

我已经尝试了所有给出的答案,但无法解决此错误。 请帮忙。

trans by 2020-08-12T04:06:58Z

Gradle构建空控制台obj

我正在尝试使用gradle堆栈中的示例获取gradle构建以在控制台上提示输入密码

当我有如下声明时:

def password = System.console().readLine("Enter keystore password ")

运行时出现错误

Cannot invoke method readLine() on null object

看来控制台以null的形式出现。我读到的内容需要Java 6,如果我进入命令提示符并键入java -version,则我正在运行Java(TM)SE运行时环境(内部版本1.6.0_27-b07)。

在Gradle的Github存储库中已跟踪了此问题:不能在Gradle守护进程中使用System.console()。

trans by 2020-08-11T16:51:19Z

在Android Gradle proj中复制APK文件

我试图将自定义任务添加到我的Android项目的build.gradle中,以将最终的APK和Proguard的publish复制到另一个目录中。 我的任务取决于assemble任务:

task publish(dependsOn: 'assembleDevDebug') << {
    description 'Copies the final APK to the release directory.'

    ...
}

我可以根据文档查看如何使用标准publish任务类型进行文件复制:

task(copy, type: Copy) {
    from(file('srcDir'))
    into(buildDir)
}

但是,前提是您知道要复制的文件的名称和位置。

如何查找作为publish任务的一部分而构建的APK文件的确切名称和位置? 这可以作为财产使用吗? 感觉好像我应该能够将文件声明为任务的输入,并将其声明为assemble任务的输出,但我的Gradle-fu不够强大。

我有一些自定义逻辑将版本号注入APK文件名,因此我的publish任务不能只是假设默认名称和位置。

trans by 2020-08-10T08:00:23Z

gradle-如何在安装新版本之前从设备自动卸载android应用

我正在将Android Studio与Gradle构建一起使用。 我在设备上测试我的应用程序,然后让Android Studio和Gradle构建应用程序并将其安装在设备上。 如何在安装新版本之前告诉Gradle或Android Studio从设备上卸载应用程序?

trans by 2020-08-10T07:07:48Z

Android 4上的Android Studio出现NoClassDefFoundError

我正在将现有应用程序从Eclipse转换为Android Studio。 但是,当我在运行4.x的设备上运行它(我已经在模拟器上测试了多个版本)时,它立即崩溃,并显示Parcelable.CREATOR

我尝试注释掉对它找不到的类的引用,但是总有另一个。 据所知,违规类总是

  1. 用我自己的代码
  2. 内部类(更新:经过更多调查,这个并不总是正确的)

在5.0.1模拟器上一切正常(我没有要测试的设备)。 我的Parcelable.CREATOR文件相当长,但是看起来像这样:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

def AAVersion = "2.7.1"

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.myapp.android"
        minSdkVersion 8
        targetSdkVersion 19
        multiDexEnabled = true
    }

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

    packagingOptions {
        *snip*
    }
}

buildscript {
    repositories {
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    maven {
        url "https://repo.commonsware.com.s3.amazonaws.com"
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'com.pact.android'
    }
}

dependencies {
    *snip compile project(':...') declarations

    apt "com.googlecode.androidannotations:androidannotations:$AAVersion"
    compile "com.googlecode.androidannotations:androidannotations-api:$AAVersion"

    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.android.gms:play-services:3.1.36'

    *snip many more compile declarations*

    compile fileTree(dir: 'libs', include: ['*.jar'])
}

引起麻烦的类的一些示例:

  • 一个实现Facebook库内部接口的匿名类(作为库项目)
  • Parcelable.CREATOR我的模型中的实现
  • 扩展android.os.Library的内部类
  • 我自己的代码中的内部类
  • 在Maven的库中实现接口的类

怎么了,我该如何解决?

trans by 2020-08-09T05:18:18Z

带有Jadle 0.10.0的Jacoco:远程对象不存在

2014年10月21日更新:已使用buildtools 21解决了该问题。

2014年9月18日更新:问题的状态已更新为FutureRelease

更新:我听说这可能不适用于Dagger,并且由于Espresso使用Dagger,因此可能会引起一些问题。 一个错误已提交给Gradle团队。


Google最近将其Gradle实施更新为0.10.0。 他们现在提供的一件事是Jacoco支持。 为此,他们提到设置以下内容:

testCoverageEnabled = true

进入您的构建类型。 现在,当我运行Espresso测试(使用build.gradle)时,在开始运行:connectedAndroidTest任务时,我得到了正确的错误,该任务指出:

Tests on HTC One - 4.2.2 - API 17 - 1080x1920 - 4.2.2 failed: Instrumentation run failed due to 'java.lang.VerifyError'
01:38:31 E/Device: Error during Sync: Remote object doesn't exist!
null
java.io.IOException: com.android.ddmlib.SyncException: Remote object doesn't exist!
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:114)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:158)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:42)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.ddmlib.SyncException: Remote object doesn't exist!
at com.android.ddmlib.SyncService.pullFile(SyncService.java:314)
at com.android.ddmlib.Device.pullFile(Device.java:849)
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:107)
... 8 more
:connectedAndroidTest FAILED

以下是我在build.gradle文件中更改的部分:

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
        ...
    }
    ...
}

android {
    buildTypes {
        debug {
            testCoverageEnabled = true
            ...
        }
        ....
    }
    ...
}

为了让Jacoco工作,是否需要更新其他文件build.gradle

该错误提到“远程对象”不存在。 通常,我将此归因于仿真器不同步,并且重新启动会解决该问题。 但是我已经尝试过了,但是也没有用。 任何想法错误试图告诉我吗?

trans by 2020-08-07T07:03:16Z

lambda表达式与retrolambd一起使用时,lint崩溃

我正在尝试将gratro-retrolambda插件与retrolambda一起使用。 总的来说,它可以正常工作,但是当我进行发行时,build.gradle阶段失败,但出现以下异常:

:playground.dagger:lintVitalReleaseFailed converting ECJ parse tree to Lombok for file D:\....\playground\dagger\MainActivity.java
java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression
    at lombok.ast.ecj.EcjTreeVisitor.visitOther(EcjTreeVisitor.java:368)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:364)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMessageSend(EcjTreeConverter.java:1042)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:156)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.toBlock(EcjTreeConverter.java:397)
    at lombok.ast.ecj.EcjTreeConverter.access$1500(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMethodDeclaration(EcjTreeConverter.java:1241)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:152)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.createNormalTypeBody(EcjTreeConverter.java:563)
    at lombok.ast.ecj.EcjTreeConverter$2.visitTypeDeclaration(EcjTreeConverter.java:486)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:48)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitCompilationUnitDeclaration(EcjTreeConverter.java:441)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:264)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at com.android.tools.lint.EcjParser.parseJava(EcjParser.java:407)
    at com.android.tools.lint.client.api.JavaVisitor.visitFile(JavaVisitor.java:236)
    at com.android.tools.lint.client.api.LintDriver.checkJava(LintDriver.java:1491)
    at com.android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.java:1026)
    at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.java:882)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:433)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:374)
    at com.android.tools.lint.LintCliClient.run(LintCliClient.java:130)
    at com.android.build.gradle.internal.LintGradleClient.run(LintGradleClient.java:112)
    at com.android.build.gradle.internal.LintGradleClient$run.call(Unknown Source)
    at com.android.build.gradle.tasks.Lint.runLint(Lint.groovy:198)
    at com.android.build.gradle.tasks.Lint.this$4$runLint(Lint.groovy)
    at com.android.build.gradle.tasks.Lint$this$4$runLint$1.callCurrent(Unknown Source)
    at com.android.build.gradle.tasks.Lint.lintSingleVariant(Lint.groovy:173)
    at com.android.build.gradle.tasks.Lint$lintSingleVariant$0.callCurrent(Unknown Source)
    at com.android.build.gradle.tasks.Lint.lint(Lint.groovy:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
    at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

有什么关系吗? 当然,一个简单的解决方法是禁用build.gradle检查发布。 但我正在寻找解决方案,允许保留lint

以下是应用程序的模块build.gradle

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'

configurations {
    apt
}

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

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

repositories {
    maven{
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
    compile 'de.greenrobot:eventbus:2.4.0'
    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:1.8.1'
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath 'me.tatarka:gradle-retrolambda:2.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
trans by 2020-08-06T00:47:16Z

无法应用插件Android Gradle插件3.0.0-alpha5不能应用于proj

使用最新的Android Studio 3.0 Canary 5

这是错误:

错误:(1,1)评估项目':app'时发生问题。

无法应用插件[类'com.android.build.gradle.api.AndroidBasePlugin'] Android Gradle插件3.0.0-alpha5不得应用于项目[path_to_my_project],因为版本3.0.0-alpha5已应用于该项目

尝试过:清洁,重建,打开/关闭。 不工作

有任何想法吗 ?

[最新编辑]解决方案:迁移到Canary 8+,一切正常。

trans by 2020-08-03T01:10:32Z

android-invokedynamic需要--min-sdk-version> = 26

今天下载了Studio 3.0 beta 2.0版本,此后试图在其中打开一个现有项目并遇到了一些困难,其中大多数我可以借助Google和Stack Overflow解决,但我不能解决。

Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: org.gradle.tooling.BuildException: com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)

同时发布我的应用程序gradle

apply plugin: 'com.android.application'
   android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

defaultConfig {
    applicationId "com.intersoft.snappy"
    minSdkVersion 19
    targetSdkVersion 22
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
}
buildTypeMatching 'dev', 'debug'
buildTypeMatching 'qa', 'debug'
buildTypeMatching 'rc', 'release'
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] 
} }
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/ashokslsk/CheckableView' }
maven { url "https://maven.google.com" }

}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.github.mrengineer13:snackbar:1.2.0'
implementation 'com.android.support:recyclerview-v7:26.0.1'
implementation 'com.android.support:cardview-v7:26.0.1'
implementation 'com.android.support:design:26.0.1'
implementation 'com.android.support:percent:26.0.1'
implementation 'dev.dworks.libs:volleyplus:+'
implementation 'com.google.guava:guava:21.0'
implementation 'com.facebook.fresco:fresco:1.0.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.wdullaer:materialdatetimepicker:3.1.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.stfalcon:frescoimageviewer:0.4.0'
implementation 'com.github.piotrek1543:CustomSpinner:0.1'
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.github.satyan:sugar:1.4'
implementation 'com.hedgehog.ratingbar:app:1.1.2'
implementation project(':sandriosCamera')
implementation('org.apache.httpcomponents:httpmime:4.2.6') {
    exclude module: 'httpclient'
}
implementation 'com.googlecode.json-simple:json-simple:1.1'
}

afterEvaluate {
tasks.matching {
    it.name.startsWith('dex')
}.each { dx ->
    if (dx.additionalParameters == null) {
        dx.additionalParameters = ['--multi-dex']
    } else {
        dx.additionalParameters += '--multi-dex'
    }
}
}
subprojects {
project.plugins.whenPluginAdded { plugin ->
    if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
        project.android.dexOptions.preDexLibraries = false
    } else if 
("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
        project.android.dexOptions.preDexLibraries = false
    }
}
}

buildscript {
repositories {
    mavenCentral()
}

dependencies {
    classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}

apply plugin: 'com.jakewharton.hugo'

还有我的另一个模块gradle

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

buildscript {
repositories {
    jcenter()
    jcenter()
    maven { url "https://maven.google.com" }
}
dependencies {
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}

group = 'com.sandrios.android'
version = '1.0.8'

ext {
PUBLISH_GROUP_ID = 'com.sandrios.android'
PUBLISH_ARTIFACT_ID = 'sandriosCamera'
PUBLISH_VERSION = '1.0.8'
PUBLISH_CODE = 9
}

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 25
    versionCode PUBLISH_CODE
    versionName PUBLISH_VERSION
}

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

task generateSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}

task generateJavadocs(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath()
        .join(File.pathSeparator))
}

task generateJavadocsJar(type: Jar) {
from generateJavadocs.destinationDir
classifier 'javadoc'
}

generateJavadocsJar.dependsOn generateJavadocs

artifacts {
archives generateSourcesJar
archives generateJavadocsJar
}

install {
repositories.mavenInstaller {
    pom.project {
        name PUBLISH_GROUP_ID
        description 'Simple integration of universal camera in android for easy image and video capture.'
        url 'https://github.com/sandrios/sandriosCamera'
        inceptionYear '2016'

        packaging 'aar'
        version PUBLISH_VERSION

        scm {
            connection 'https://github.com/sandrios/sandriosCamera.git'
            url 'https://github.com/sandrios/sandriosCamera'

        }
        developers {
            developer {
                name 'arpitgandhi9'
            }
        }
    }
}
}

bintray {
Properties properties = new Properties()

properties.load(project.rootProject.file('local.properties').newDataInputStream())
user = properties.getProperty('bintray.user')
key = properties.getProperty('bintray.apikey')
configurations = ['archives']
pkg {
    repo = 'android'
    name = 'sandriosCamera'
    userOrg = 'sandriosstudios'
    desc = 'Android solution to simplify work with different camera apis.'
    licenses = ['MIT']
    labels = ['android', 'camera', 'photo', 'video']
    websiteUrl = 'https://github.com/sandrios/sandriosCamera'
    issueTrackerUrl = 'https://github.com/sandrios/sandriosCamera/issues'
    vcsUrl = 'https://github.com/sandrios/sandriosCamera.git'
    version {
        name = PUBLISH_VERSION
        vcsTag = PUBLISH_VERSION
        desc = 'Minor fixes.'
        released = new Date()
    }
}
}

repositories {
jcenter()
}

dependencies {
implementation 'com.android.support:support-v4:26.0.0'
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support:recyclerview-v7:26.0.0'
implementation 'com.github.bumptech.glide:glide:3.6.1'
implementation 'com.yalantis:ucrop:2.2.0'
implementation 'gun0912.ted:tedpermission:1.0.2'
}

以及项目级别的gradle

// Top-level build file where you can add configuration options common to 
all sub-projects/modules.

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-beta2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}
}

请帮助我摆脱这个错误

trans by 2020-08-02T23:55:55Z

Android上使用不同键的Gradle签名风格

我的Android应用程序有很多风格,除了一种之外,我都希望所有人都使用相同的键。 有一个需要使用其他密钥。

如何仅对应用程序的1种样式(但在相同的构建类型,例如“发行版”)中覆盖build.gradle

  • 我希望默认情况下所有版本都使用主发行版配置。
  • 我只想改写1种口味
  • 我希望能够使用单个build.gradle命令运行所有发行版

最后一点很重要,因为我目前有超过120种不同的口味并在不断发展。 为了分别自定义每种口味,需要做很多额外的工作。


我尝试过的相关文章:

从单个构建类型生成使用不同密钥签名的多个构建

  • 这需要针对每种口味进行配置
  • 它似乎并没有使用我的自定义build.gradle

用gradle签名产品口味

  • 接受的解决方案不起作用(对我来说)
  • 根据评论,可以通过将build.gradle放在productFlavors内来实现,但我不知道该怎么做。

在Gradle产品口味上调试签名配置

  • 如博客文章中所述:使用Gradle构建Android应用的多个版本
  • 它实际上不起作用,它完美地起作用
  • 但是它不能很好地适应119种口味

总体而言,每个解决方案似乎仍使用默认的发行版配置,而不是我的自定义配置。


我的build.gradle的重要部分如下所示:

signingConfigs {
    releaseConfig {
        storeFile file('key')
        storePassword "pass"
        keyAlias "alias"
        keyPassword "pass"
    }

    custom {
        storeFile file('custom_key')
        storePassword "pass"
        keyAlias "alias"
        keyPassword "pass"
    }
}

productFlavors {
    apple {
        applicationId "demo.apple"
    }
    banana {
        applicationId "demo.banana"
    }

    // def customConfig = signingConfigs.custom
    custom {
        applicationId "custom.signed.app"
        // signingConfig customConfig
    }
 }


buildTypes {
    debug {
        applicationIdSuffix ".debug"
    }
    release {
         signingConfig signingConfigs.releaseConfig
         // productFlavors.custom.signingConfig signingConfigs.custom
    }
}
trans by 2020-08-01T21:43:51Z

android-Robolectric说“找不到AndroidManifest.xml”

尝试让Robolectric RC3在Android Studio中工作时,我得到

Caused by: java.lang.RuntimeException: build/intermediates/bundles/debug/AndroidManifest.xml not found or not a file; it should point to your project's AndroidManifest.xml
at org.robolectric.manifest.AndroidManifest.validate(AndroidManifest.java:120)
at org.robolectric.manifest.AndroidManifest.getResourcePath(AndroidManifest.java:469)
at org.robolectric.manifest.AndroidManifest.getIncludedResourcePaths(AndroidManifest.java:475)
at org.robolectric.RobolectricTestRunner.createAppResourceLoader(RobolectricTestRunner.java:479)
at org.robolectric.RobolectricTestRunner.getAppResourceLoader(RobolectricTestRunner.java:471)
at org.robolectric.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:73)
at org.robolectric.RobolectricTestRunner.setUpApplicationState(RobolectricTestRunner.java:421)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234)

我试过了

@Config(manifest = "app/src/main/AndroidManifest.xml", constants = BuildConfig.class, sdk=21)

我尝试在TestRunner中设置清单位置,但没有任何效果。 在文件系统中,我看到清单位于

./app/build/intermediates/manifests/full/debug/AndroidManifest.xml

不在Robolectric寻找的位置。在某个时候,清单只是被忽略了,然后资源出现了类似的问题,该应用程序或Robolectric找不到我的应用程序使用的原始资源。这是在我的构建文件中:

   sourceSets {
    main {
        java.srcDirs = ['src/main/java']
        resources.srcDirs = ['src/main/res']
    }
    test {
        java.srcDirs = ['src/test/java', 'src/main/java']
        resources.srcDirs = ['src/test/res', 'src/main/res']
    }
}

我如何告诉Robolectric在哪里寻找清单,更重要的是,在哪里寻找资源?

编辑:我已经从github中签出了Robolectric,我已经构建了它,并将其安装在本地.m2存储库中,gradle文件现在引用了本地SNAPSHOT构建,并且我确保Gradle不会从远程存储库获得新版本 。 然后,我将RobolectricGradleTestRunner复制到我的项目中,更改了定义文件位置的行:它不包含模块名称。 现在可以了。

trans by 2020-08-01T21:13:34Z

“指定的Android SDK Build Tools版本(26.0.0)被忽略...”

在Android Studio 3中,我看到了以下问题:

指定的Android SDK生成工具版本(26.0.0)将被忽略,因为 它低于Android Gradle的最低支持版本(26.0.2) 插件3.0.0。

将使用Android SDK Build Tools 26.0.2。

要取消显示此警告,请从以下位置删除“ buildToolsVersion '26 .0.0'” 您的build.gradle文件,作为每个版本的Android Gradle插件 现在具有构建工具的默认版本。

问题是,因为这些是具有buildToolsVersion的第三方/供应商模块,所以我不能在不分叉每个子模块的情况下修改它们的build.gradle。

有没有办法设置一个全局buildToolsVersion,它将覆盖所有子build.gradles?

trans by 2020-08-01T09:17:11Z

Gradle警告:缺少groovy返回语句

我的gradle构建文件中出现以下警告

并非所有执行路径都返回值

该检查报告在方法返回的末尾缺少常规返回语句

这是该文件中的代码

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "ac.company.srikar.quickhelpindia"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        android {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
    }
}

任何人都可以说出这里的问题是什么以及如何消除此警告。

trans by 2020-07-31T01:31:42Z

gradle-如何将Android支持存储库添加到Android Studio?

我将Android Studio与外部Android SDK结合使用。 我已经安装了支持库和支持库。 支持资料库位于:

~/Development/Tools/android/sdk/extras/android/m2repository

当我向build.gradle文件中的支持库添加依赖项时,例如:

...

repositories {
    mavenCentral()
}

...

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

Android Studio无法找到支持库(无法解析符号等),并且Gradle也无法找到库:

Gradle: A problem occurred configuring project ':TestAndroidStudio'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':TestAndroidStudio:_DebugCompile'.
      > Could not find any version that matches com.android.support:support-v4:18.0.+.
        Required by:
            TestAndroidStudio:TestAndroidStudio:unspecified

如何在Android Studio和/或build.gradle文件中指定Android支持存储库的位置?

trans by 2020-07-30T20:52:26Z

android-无法为ApkVariantOutputImpl_Decorated设置只读属性'outputFile'的值

我在gradle脚本中使用以下代码来重命名由AndroidStudio生成的apk:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFile = new File(output.outputFile.parent, defaultConfig.versionCode + "_" + output.outputFile.name)
    }
}

因此它生成的apk的名称如下:345-app-release.apk,其中345是versionCode。

但是更新到Android Studio 3.0后,它会返回以下错误:

无法为设置只读属性'outputFile'的值 ApkVariantOutputImpl_Decorated {apkData = Main {type = MAIN,fullName = debug, 过滤器= []}}类型 com.android.build.gradle.internal.api.ApkVariantOutputImpl。

如何使用新的构建工具实现类似的重命名。

trans by 2020-07-27T15:23:05Z

android-为什么在应用程序处于调试状态时,Gradle会在发布模式下构建我的模块

我正在制作一个新的Android项目,其中包含标准的2977985406018520062006模块以及一个库项目(称为custom_lib)。 在appbuild.gradle文件中,我这样链接模块:

dependencies {
    compile project(':custom_lib')
}

当我触发构建过程时(菜单:app:preReleaseBuild> custom_lib),我在Gradle控制台中获得以下输出

Executing tasks: [clean, :app:compileDebugSources, :custom_lib:compileDebugSources]

Configuration on demand is an incubating feature.
:app:clean
:custom_lib:clean
:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:custom_lib:compileLint
:custom_lib:copyReleaseLint UP-TO-DATE
:custom_lib:mergeReleaseProguardFiles UP-TO-DATE
:custom_lib:preBuild
:custom_lib:preReleaseBuild
:custom_lib:checkReleaseManifest
:custom_lib:prepareReleaseDependencies
:custom_lib:compileReleaseAidl
:custom_lib:compileReleaseRenderscript
:custom_lib:generateReleaseBuildConfig
:custom_lib:generateReleaseAssets UP-TO-DATE
:custom_lib:mergeReleaseAssets
:custom_lib:generateReleaseResValues UP-TO-DATE
:custom_lib:generateReleaseResources
:custom_lib:packageReleaseResources
:custom_lib:processReleaseManifest
:custom_lib:processReleaseResources
:custom_lib:generateReleaseSources
:custom_lib:compileReleaseJava
:custom_lib:processReleaseJavaRes UP-TO-DATE
:custom_lib:packageReleaseJar
:custom_lib:compileReleaseNdk
:custom_lib:packageReleaseJniLibs UP-TO-DATE
:custom_lib:packageReleaseLocalJar UP-TO-DATE
:custom_lib:packageReleaseRenderscript UP-TO-DATE
:custom_lib:bundleRelease
:app:prepareComAndroidSupportAppcompatV72102Library
:app:prepareComAndroidSupportSupportV42102Library
:app:prepareTestDoubleBuildCustom_libUnspecifiedLibrary
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava
:app:compileDebugNdk
:app:compileDebugSources
:custom_lib:preDebugBuild
:custom_lib:checkDebugManifest
:custom_lib:prepareDebugDependencies
:custom_lib:compileDebugAidl
:custom_lib:compileDebugRenderscript
:custom_lib:generateDebugBuildConfig
:custom_lib:generateDebugAssets UP-TO-DATE
:custom_lib:mergeDebugAssets
:custom_lib:generateDebugResValues UP-TO-DATE
:custom_lib:generateDebugResources
:custom_lib:packageDebugResources
:custom_lib:processDebugManifest
:custom_lib:processDebugResources
:custom_lib:generateDebugSources
:custom_lib:compileDebugJava
:custom_lib:compileDebugNdk
:custom_lib:compileDebugSources

BUILD SUCCESSFUL

Total time: 2.184 secs

让我感到困惑的是,构建机制触发了Debug构建(如第一行所说),但是几乎立即,Gradle使用了:app:preReleaseBuild任务,该任务使我的custom_lib模块使用Release配置进行构建。

然后,在应用程序完全构建后,Gradle使用Debug配置编译我的模块。

所以我的问题是:

  • 为什么要进行这种看起来不连贯的双重构建?
  • 启动调试构建过程时,如何确保使用调试配置来构建库?

编辑:

app / build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.deezer.testdoublebuild"
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        debug{
            debuggable true
        }
        release {
            debuggable false
            minifyEnabled false
        }
    }
}

dependencies {
    compile project(':custom_lib')
}

custom_lib / build.gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.deezer.mylibrary"
        minSdkVersion 8
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
}

注意:我使用的是Android Studio 1.0 RC 1 / Gradle 2.2,并通过从头开始创建新项目,添加空的Android库模块和“瞧”来重现此问题。

trans by 2020-07-22T17:38:31Z

commons-logging定义了与Android Studio Upd之后由Android现在提供的类冲突的类

我已将Android Studio更新至版本3,现在似乎无法编译以前编译的项目而没有错误。

错误消息如下

错误:错误:commons-logging定义了与之冲突的类 现在由Android提供的类。 解决方案包括寻找更新的 没有相同问题的版本或替代库 (例如,对于httpclient,请使用HttpUrlConnection或okhttp代替), 或使用jarjar之类的东西重新打包库。 [DuplicatePlatformClasses]

依赖项是

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:27.0.0'
    compile 'com.android.support:design:27.0.0'
    compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
    compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
    compile 'com.google.firebase:firebase-core:11.4.2'
}

错误似乎是由

compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'

我已经用过exclude module: 'httpclient'那为什么它不编译呢?这是Android Studio 3的错误,并且/还是包含com.android.tools.build:gradle:3.0.0插件,还是我丢失了某些东西? 使用以前的版本,完全可以编译相同的项目。

trans by 2020-07-20T08:15:09Z

无法正确创建BuildConfig(Android版)

我正在尝试将我们的Android应用程序转换为gradle构建。 我有这个项目,它的图书馆建设成功。 现在,我正在尝试为我们的各种环境创建单独的apk(dev / test / prod对于它们消耗的静态服务具有不同的url)。

在搜索时,我觉得最好的方法是为每个环境创建不同的BuildConfig。 这是我尝试的:

import java.util.regex.Pattern

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:+'
    }
}

apply plugin: 'android'

task('increaseVersionCode') << {
    def manifestFile = file("AndroidManifest.xml")
    def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
    def manifestText = manifestFile.getText()
    def matcher = pattern.matcher(manifestText)
    matcher.find()
    def versionCode = Integer.parseInt(matcher.group(1))
    def manifestContent = matcher.replaceAll("versionCode=\"" + ++versionCode + "\"")
    manifestFile.write(manifestContent)
}

tasks.whenTaskAdded { task ->
    if (task.name == 'generateReleaseBuildConfig') {
        task.dependsOn 'increaseVersionCode'
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.0.0' 
    compile files('libs/commons-io-2.4.jar',
                  'libs/google-play-services.jar',
                  'libs/gson-2.2.4.jar',
                  'libs/universal-image-loader-1.8.6.jar',
                  'libs/wakeful-1.0.1.jar')
    compile project(':pulltorefresh_lib')
    compile project(':edgeeffect_lib')
    compile project(':viewpagerindicator_lib')        
}

android {
    buildToolsVersion "18.1.1"
    compileSdkVersion "Google Inc.:Google APIs:18"

    defaultConfig { 
       minSdkVersion 14
       targetSdkVersion 18
    }

    buildTypes {
        debug {
            packageNameSuffix ".debug"
        }
        dev.initWith(buildTypes.debug)
        dev {
            buildConfigField "String", "URL_SEARCH", "\"https://dev-search.example.com\";"
            buildConfigField "String", "URL_CONNECT", "\"https://dev-connect.example.com\";"
            buildConfigField "String", "URL_SVC_NEWSLIST", "\"https://dev-mobilenews.example.com/newslist\";"
            buildConfigField "String", "URL_SVC_NEWSDETAIL", "\"https://dev-mobilenews.example.com/newsdetail\";"
            buildConfigField "String", "URL_SVC_REGISTERENDPOINTS", "\"https://dev-mobilenews.example.com/registerendpoints\";"
        }
        prod.initWith(buildTypes.release)
        prod {
            buildConfigField "String", "URL_SEARCH", "\"https://search.example.com\";"
            buildConfigField "String", "URL_CONNECT", "\"https://connect.example.com\";"
            buildConfigField "String", "URL_SVC_NEWSLIST", "\"https://mobilenews.example.com/newslist\";"
            buildConfigField "String", "URL_SVC_NEWSDETAIL", "\"https://mobilenews.example.com/newsdetail\";"
            buildConfigField "String", "URL_SVC_REGISTERENDPOINTS", "\"https://mobilenews.pdc-np-cf.lmig.com/registerendpoints\";"          
        }
    }

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

问题是我的BuildConfig.java似乎没有注入静态变量,因此出现类似以下的错误:

/Users/path/to/project/MainActivity.java:348: error: cannot find symbol
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.URL_SEARCH)));
                                                                              ^
  symbol:   variable URL_SEARCH
  location: class BuildConfig
/Users/path/to/project/MainActivity.java:359: error: cannot find symbol
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(BuildConfig.URL_CONNECT)));
                                                                              ^
  symbol:   variable URL_CONNECT
  location: class BuildConfig
/Users/path/to/project/MainActivity.java:600: error: cannot find symbol
            HttpPost httpPost = new HttpPost(BuildConfig.URL_SVC_REGISTERENDPOINTS);
                                                        ^
  symbol:   variable URL_SVC_REGISTERENDPOINTS
  location: class BuildConfig
/Users/path/to/project/service/AlarmNotificationService.java:145: error: cannot find symbol
        String requestUrl = BuildConfig.URL_SVC_NEWSLIST + "?"
                                       ^
  symbol:   variable URL_SVC_NEWSLIST
  location: class BuildConfig
/Users/path/to/project/service/NewsService.java:240: error: cannot find symbol
        String requestUrl = BuildConfig.URL_SVC_NEWSLIST + "?"
                                       ^
  symbol:   variable URL_SVC_NEWSLIST
  location: class BuildConfig
/Users/path/to/project/service/NewsService.java:530: error: cannot find symbol
            HttpPost httpPost = new HttpPost(BuildConfig.URL_SVC_NEWSDETAIL);
                                                        ^
  symbol:   variable URL_SVC_NEWSDETAIL
  location: class BuildConfig
6 errors

我的build / source / buildConfig / debug / com /.../ BuildConfig.java文件包含:

/**
 * Automatically generated file. DO NOT MODIFY
 */
package com....;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String PACKAGE_NAME = "com.....debug";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 5;
}

我究竟做错了什么?

trans by 2020-07-20T00:18:40Z

无法解决:com.android.support:appcompat-v7:25.1.0

enter image description here我的Android Studio充满错误android studio无法识别库。

Error:(27, 13) Failed to resolve: com.android.support:appcompat-v7:25.1.0
trans by 2020-07-12T22:15:48Z

Android Studio与带有ADT的Eclipse(2015)

截至2015年,我看到Android Studio是一个官方IDE,用于根据其官方网站和网站每个页面上的信息开发android应用程序,其中有一条注释建议使用Android Studio而不是带有ADT的Eclipse。

注意:如果您一直在使用带有ADT的Eclipse,请注意Android Studio现在是Android的正式IDE,因此您应该迁移到Android Studio以接收所有最新的IDE更新。

但是我还没有找到任何有关选择IDE或使用ADT进行调试的利弊的最新文章。 如果有人可以对此有所了解,那么它将帮助像我这样的其他初学者选择适合Android开发的应用

trans by 2020-07-11T17:25:57Z

1 2 3 4 下一页 共4页