I have imported a code from github in my git repo and from there I have imported the project in Android Studio but after the gradle build at the time of gradle sync it is giving this error :-
Error:(12, 0) CreateProcess error=2, The system cannot find the file specified Open File
Can anyone help please fast .
this is my build.gradle file
if ((new File(gradle.local)).exists()) {
apply from: gradle.local
} else {
apply from: gradle.remote
}
applicationScripts.each {
apply from: it
}
apply plugin: 'com.android.application'
com.android.ddmlib.DdmPreferences.setTimeOut(60000)
android {
// The following are set in the common.gradle file
compileSdkVersion(compileVersion)
buildToolsVersion(buildTools)
defaultConfig {
applicationId("org.odk.collect.android")
minSdkVersion(9)
targetSdkVersion(9)
versionCode(1061)
versionName("1.4.10")
}
productFlavors {
demo {
}
master {
}
snapshot {
}
uitest {
}
}
signingConfigs {
release {
if (shouldSign) {
storeFile file(signStoreFilePath)
storePassword signStorePass
keyAlias signKeyAlias
keyPassword signKeyPass
}
}
}
buildTypes {
release {
minifyEnabled(minify)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
if (shouldSign) {
signingConfig signingConfigs.release
}
}
debug {
debuggable(true)
testCoverageEnabled(testCoverage) // Allows AndroidTest JaCoCo reports to be generated
}
}
packagingOptions { // Pick first occurrence of any files that cause conflicts, as defined in common.gradle
packageList.each {
pickFirst it
}
}
compileOptions {
sourceCompatibility javaVersion
targetCompatibility javaVersion
}
}
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(0, 'seconds')
cacheChangingModulesFor(0, 'seconds')
}
transitive = true
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.android.gms:play-services:4.1.32'
// Testing-only dependencies
testCompile 'junit:junit:4.12'
}
Related
Facing errors on my Gradle build in Android Studio. Where do I need to change the code to fix the issue? I am new to android app development.
This is my project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
allprojects {
repositories {
jcenter()
google()
maven { url 'https://jitpack.io' }
}
}
this is my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.cisco.amp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "2.0.0.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// Override versionName and versionCode if passed as arguments from build script
if (project.hasProperty("versionName")) {
versionName = project.property("versionName")
}
if (project.hasProperty("versionCode")) {
def versionCodeStr = project.property("versionCode")
if (versionCodeStr != null && !versionCodeStr.equals("")) {
versionCode = Integer.valueOf(versionCodeStr)
}
}
}
signingConfigs {
release {
if (project.hasProperty("keyAlias")) {
keyAlias = project.property("keyAlias")
}
if (project.hasProperty("keyPassword")) {
keyPassword = project.property("keyPassword")
}
if (project.hasProperty("storeFile")) {
storeFile = file(project.property("storeFile"))
}
if (project.hasProperty("storePassword")) {
storePassword = project.property("storePassword")
}
}
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
flavorDimensions "buildMode"
productFlavors {
automation {
dimension "buildMode"
applicationIdSuffix ".automation"
versionNameSuffix "-automation"
}
prod {
dimension "buildMode"
}
}
testOptions {
animationsDisabled true
}
jacoco {
version '0.8.4'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06'
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'androidx.annotation:annotation:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:core:1.2.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
}
Error logs:
Task :app:validateSigningAutomationRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:validateSigningAutomationRelease'.
> Keystore file not set for signing config release
Able to resolve the issue by commenting out following 2 blocks of dependencies from my app build.gradle
/*debug {
testCoverageEnabled true
}*/
and
/*jacoco {
version '0.8.4'
}*/
I'm trying to implement this approach - https://www.androidsecurity.info/2016/12/15/storing-your-secure-information-in-the-ndk/.
The moment when I add cmake path in a gradle file,
externalNativeBuild {
cmake {
path 'src/CMakeLists.txt'
}
}
building process stuck with StackOverflowError.
_
Note. If I implement that approach in a new project, everything works fine - gradle builds successfully, and native method works in java class. The problem occurs when I do the same on my "production" project with many dependencies.
As you can see gradle stuck on "resolve artifact uiautomator-v18.aar". When remove "uiautomator" from dependencies, same error appears but with "espresso-core", remove "espresso-core" - "hamcrest-library" is the next, and so on.
All module build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'kotlin-android-extensions'
androidExtensions {
experimental = true
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
repositories {
jcenter()
}
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'io.fabric.tools:gradle:1.21.4'
}
}
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
android {
lintOptions {
// google services plugin is causing missing translation issue
abortOnError false
disable 'MissingTranslation'
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.toolsVersion
signingConfigs { ... }
defaultConfig {
applicationId "..."
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
buildConfigField "boolean", "USE_ANALYTIC", "false"
buildConfigField 'boolean', 'USE_TRANSLATION', 'false'
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "USE_ANALYTIC", "true"
signingConfig signingConfigs.release
}
debug {
minifyEnabled false
debuggable true
buildConfigField "boolean", "USE_ANALYTIC", "false"
}
}
productFlavors {...}
externalNativeBuild {
cmake {
path 'src/CMakeLists.txt'
}
}
dataBinding { enabled = true }
}
configurations { ... }
dependencies {
...
// debug tools
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile rootProject.deps.firebaseMessaging
compile rootProject.deps.firebaseCore
compile rootProject.deps.firebaseConfig
compile 'com.squareup.picasso:picasso:2.5.2'
compile('com.mcxiaoke.viewpagerindicator:library:2.4.1') {
exclude module: 'support-v4';
}
compile "com.android.support:support-vector-drawable:$supportLibrary"
compile "com.android.support:animated-vector-drawable:$supportLibrary"
compile rootProject.deps.appCompat
compile rootProject.deps.cardView
compile rootProject.deps.design
compile project(':sublimepickerlibrary')
compile project(':segmentedcontrol')
compile project(':stickyheaderlist')
compile "com.android.support:customtabs:$supportLibrary"
apt rootProject.deps.daggerCompiler
testCompile rootProject.testDeps.junit
testCompile rootProject.testDeps.intellijannotations
testCompile rootProject.testDeps.mockito
testCompile rootProject.testDeps.mockitoKotlin
androidTestCompile "com.android.support:support-annotations:$supportLibrary"
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.artemzin.rxjava:proguard-rules:1.0.14.2'
compile rootProject.deps.rxAndroid
compile rootProject.deps.rxJava
}
configurations.all {
resolutionStrategy {
force "org.mockito:mockito-core:$mockito",
"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.google.gms.google-services'
Appreciate any help - either direct answer or at least point out where to research.
I have one flavor for specific device. For this device I have .jar file which have custom android sdk(for this device. It contains some custom class which I have to use). And it works fine until I start use proguard. When I build project with proguard I receive this:
...
Note: there were 1504 duplicate class definitions.
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:proguardAppProguard'.
> java.io.IOException: Please correct the above warnings first.
I found that adding a string:
-ignorewarnings
to proguard-android.txt fixes this problem, but it looks like bad solution. Did somebody face this(or similar) problem?
Edit
build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
flatDir {
dirs 'libs'
}
}
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
def computeVersionName() {
return "r_1.0"
}
android {
compileSdkVersion 23
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.app"
multiDexEnabled true
String buildSuf = System.getenv("BUILD_NUMBER");
ext.defaultName = project.archivesBaseName;
if (buildSuf != null) {
def vers = Integer.parseInt(buildSuf)
println "VERCODE = ${vers}"
versionCode vers
} else {
versionCode 1000
}
minSdkVersion 16
targetSdkVersion 21
}
productFlavors {
app {
applicationId "com.app"
versionName computeVersionName()
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
disable 'InvalidPackage'
}
signingConfigs {
...
customerProgurd {
storeFile file('../keys/debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
...
}
buildTypes {
...
customerProguard {
debuggable false
jniDebuggable false
minifyEnabled true
proguardFiles rootProject.file('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.customerProgurd
}
...
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
...
app files('libs/classes.jar') // it's custom sdk
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
...
}
I've regularly used the archivesbasename to rename my output apk's but since using the google-services plugin it is being ignored. Is there anything I can do to get this working again.
Attached my full build.gradle below, be grateful for any pointers.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
project.archivesBaseName = "MyApp";
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "org.codechimp.myapp"
versionCode 205
versionName "2.4"
minSdkVersion 14
targetSdkVersion 22
}
productFlavors {
prod {
}
dev {
versionName = android.defaultConfig.versionName + " dev"
}
}
signingConfigs {
debug {
storeFile file("debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release }
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:22.2.0'
compile 'com.google.android.gms:play-services-drive:7.5.0'
compile 'com.google.android.gms:play-services-plus:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-ads:7.5.0'
compile 'com.google.android.gms:play-services-identity:7.5.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.afollestad:material-dialogs:0.6.2.4'
compile 'com.google.code.gson:gson:2.3'
compile 'com.github.andrew-codechimp:androidutils:1.19'
}
def Properties props = new Properties()
props.load(new FileInputStream(file('signing.properties')))
if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
android.buildTypes.release.signingConfig = null
}
Project level build.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:1.2.3'
classpath 'com.google.gms:google-services:1.3.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
This stopped working for me with android gradle plugin version 1.3.0 using 1.3.1 resolves it.
classpath 'com.android.tools.build:gradle:1.3.1'
Inside your build.gradle for the app you might have this.
android {
//...
defaultConfig {
//...
archivesBaseName = "myprojectname_v${versionName}_${versionCode}"
}
//...
}
If you want to change the APK name based on build type.
android {
//...
buildTypes {
special {
//...
archivesBaseName = "myprojectname_special_v${versionName}_${versionCode}"
}
}
//...
}
I want to use both evant/gradle-retrolambda and RoboBinding/RoboBinding in my android project.
When adding RoboBinding to your project, you can choose to use it with AspectJ using RoboBinding/RoboBinding-aspectj-plugin. However, whenever I turn it on, the lambda expressions in my code produce this compile error:
Error:error at (no source information available)
/mnt/FCEE58DAEE588F30/AndroidstudioProjects/SpeechACall/app/src/main/java/com/voicesense/personality_profiling_dialer/GcmRegistrationHandler.java:1:0::0 The type java.lang.invoke.MethodHandles cannot be resolved. It is indirectly referenced from required .class files
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugAspectJ'.
> The type java.lang.invoke.MethodHandles cannot be resolved. It is indirectly referenced from required .class files
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
This is my build.gradle file
buildscript {
repositories {
mavenCentral()
maven() {
name 'RoboBinding AspectJPlugin Maven Repository'
url "https://github.com/RoboBinding/RoboBinding-aspectj-plugin/raw/master/mavenRepo"
}
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.4.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
classpath 'org.robobinding:aspectj-plugin:0.8.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'org.robobinding.android-aspectj'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.voicesense.hr_dialer"
minSdkVersion 15
targetSdkVersion 21
}
signingConfigs {
release {
storeFile file("../../../../../../home/amitai/personality-profiling-dialer_key.keystore")
storePassword System.getenv("KSTOREPWD")
keyAlias "alias_name"
keyPassword System.getenv("KEYPWD")
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda {
jvmArgs '-noverify'
}
ext {
//robobindingVersion = 'latest.integration'
robobindingVersion = '0.8.9'
}
dependencies {
compile files('libs/acra-4.5.0.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:support-v13:20.0.0'
//compile 'com.netflix.rxjava:rxjava-android:0.20.7'
compile 'io.reactivex:rxandroid:0.24.0'
//compile 'com.googlecode.libphonenumber:geocoder:2.16'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0'
compile ("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
aspectPath ("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
apt "org.robobinding:codegen:$robobindingVersion"
}
And here is a zipped Android Studio project that can be used to reproduce (contains a relevant build.gradle file and a lambda expression that fails to compile).
After some investigation I found out it had to do with AspectJ not being compatible with Java 8.
I believe Java 8 Compatiblity/Update AspectJ · Issue #22 · JakeWharton/hugo and Java 8 not supported · Issue #6 · uPhyca/gradle-android-aspectj-plugin have the same issue. Any suggestions?
I made my own plugin supports aspectj with retrolambda.
GradleAndroidAspectJPlugin
When the project is using retrolambda. You have to recompile the classes using ant iajc after retrolamda compiled.
project.configurations {
aspectjTaskClasspath
aspectsInPath
}
project.repositories {
mavenCentral()
}
def aspectjVersion = '1.8.5';
project.dependencies {
//AspectJ
aspectjTaskClasspath "org.aspectj:aspectjtools:$aspectjVersion"
compile "org.aspectj:aspectjrt:$aspectjVersion"
}
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
def buildTypeName = variant.name.capitalize()
def hasRetrolambda = project.plugins.hasPlugin('me.tatarka.retrolambda')
def copyDir = new File("${project.buildDir.absolutePath}/copyClasses")
if (copyDir.exists()) {
copyDir.deleteDir()
}
copyDir.mkdirs()
def copyClassTask = project.task("copy${buildTypeName}Classes", type: Copy) {
from variant.javaCompile.destinationDir
into copyDir
doLast {
variant.javaCompile.destinationDir.deleteDir()
variant.javaCompile.destinationDir.mkdirs()
}
}
def aspectsInPaths = [];
def aspectsInPathsAbsolute = [];
def aopTask = project.task("compile${buildTypeName}AspectJ") {
doFirst {
project.configurations.aspectsInPath.each {
aspectsInPaths.add(it);
aspectsInPathsAbsolute.add(it.absolutePath);
}
}
doLast {
ant.taskdef(
resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
classpath: project.configurations.aspectjTaskClasspath.asPath
)
ant.iajc(
source: project.android.compileOptions.sourceCompatibility,
target: project.android.compileOptions.targetCompatibility,
fork: "true",
destDir: variant.javaCompile.destinationDir,
bootClasspath: project.android.bootClasspath.join(File.pathSeparator),
inpathDirCopyFilter: "java/**/*.class"
) {
classpath {
variant.javaCompile.classpath.each {
if (!aspectsInPathsAbsolute.contains(it)) {
pathElement(location: it)
}
}
}
inpath {
pathElement(location: copyDir)
aspectsInPaths.each {
if (!it.name.startsWith("aspectjrt")) {
pathElement(location: it)
}
}
}
}
}
}
aopTask.dependsOn(copyClassTask);
def filterPreDexTask = project.task("filter${buildTypeName}PreDex") {
doLast {
def finalPreDexJars = []
project.tasks["preDex${buildTypeName}"].inputFiles.each {
if (it.name.startsWith("aspectjrt") ||
!aspectsInPathsAbsolute.contains(it.absolutePath)) {
finalPreDexJars.add(it)
}
}
project.tasks["preDex${buildTypeName}"].inputFiles = finalPreDexJars
}
}
project.tasks["preDex${buildTypeName}"].dependsOn(filterPreDexTask)
if (hasRetrolambda) {
project.tasks["compileRetrolambda$buildTypeName"].finalizedBy(aopTask)
} else {
project.tasks["compile${buildTypeName}Java"].finalizedBy(aopTask)
}
}
}