简体   繁体   中英

Build and Run an old Android Project in Android Studio

I am given the zipped project source code of an Android project integrated to AWS services. I need to understand and be able to add some new functionalities to the app but I cannot successfully run the project in android studio. I am using Android Studio 4.1.3.

I am new to Android and AWS and I am just learning these technologies.

How and where should I start studying the code?

Also if you could help me solve the issue I am encountering in Android Studio. I already tried killing all gradle daemons and killing all java processes but I still encounter the same issue.

Android Studio Issue

Unable to find method 'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;Lorg/gradle/api/internal/file/collections/DirectoryFileTreeFactory;)V' org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;Lorg/gradle/api/internal/file/collections/DirectoryFileTreeFactory;)V

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network) The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

below is the build.gradle (project)

buildscript {
ext.kotlin_version = '1.3.31'
repositories {
    google()
    jcenter()
    
}
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.amazonaws:aws-android-sdk-appsync-gradle-plugin:2.9.+'
}}
allprojects {
repositories {
    google()
    jcenter()  }}
task clean(type: Delete) {delete rootProject.buildDir}

below is the build.gradle (app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amazonaws.appsync'
android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.dostcandle.ecrf"
    minSdkVersion 24
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
dataBinding {
    enabled = true
}}
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.2.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.fragment:fragment-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.amazonaws:aws-android-sdk-core:2.15.+'
kapt "androidx.room:room-compiler:$room_version"
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.jaredrummler:material-spinner:1.3.1'
implementation 'ph.ingenuity.tableview:tableview:0.1.0-alpha'

implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.15.+'

implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.15.+'
implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.15.+'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'}

You're using an old version of the AppSync SDK that is not compatible with Android Gradle Plugin 4.x / Gradle 6+.Right now, I see that you're using AGP 4.x.

See this GitHub issue for more details.

You have two options:

  1. Use older versions of Gradle & Android Gradle Plugin. Specifically, 3.6.3 of the plugin, and 5.6.4 of Gradle.

  2. Update your AppSync dependencies to at least 3.1+. See the setup notes in the project's README for more details.

Source: I authored the fix for this issue in the AppSync SDK.

apply these:

id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.amazonaws.appsync'

instead of these:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amazonaws.appsync'

if still it does not work then simple add these:

android {
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

Create new project most of the code should be obsolete. If you want to run existing code change jcenter() to mavenCentral() also check aws documentation https://aws.amazon.com/getting-started/hands-on/build-android-app-amplify/

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.32"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

        // Add this line into `dependencies` in `buildscript`
        classpath 'com.amplifyframework:amplify-tools-gradle-plugin:1.0.2'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'com.amplifyframework.amplifytools'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.dostcandle.ecrf"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
        dataBinding true
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

    implementation 'com.amplifyframework:aws-api:1.17.3'
    implementation 'com.amplifyframework:aws-datastore:1.17.3'

    implementation 'com.jaredrummler:material-spinner:1.3.1'
    implementation 'ph.ingenuity.tableview:tableview:0.1.0-alpha'

    implementation 'com.amazonaws:aws-android-sdk-appsync:2.8.+'
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
    implementation 'com.amazonaws:aws-android-sdk-auth-ui:2.22.6'

    implementation 'com.amazonaws:aws-android-sdk-mobile-client:2.22.6'
    implementation 'com.amazonaws:aws-android-sdk-auth-userpools:2.22.6'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM