1

I am following the book Practical Android by Mark Wickham. I am trying to open the source code from the Connections app here, but am running into many problems as it's an older project(2018).

Problems

  • Stuck on the loading screen devices; cannot run project

What I've tried

In this app specifically, my screen looks like this:enter image description here

If you look at the very top, I am unable to choose any device. Please note this does not happen with any other project(tried creating blank project, problem didn't occur).

How can I run this project?

Thanks!

App build.grade:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30

    defaultConfig {
        applicationId "com.wickham.android.connections"
        minSdkVersion 19
        targetSdkVersion 30
    }

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

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def project = "Connections"
            def SEP = "_"
            def buildType = variant.variantData.variantConfiguration.buildType.name
            def version = variant.versionName
            def date = new Date();
            def formattedDate = date.format('ddMMyy_HHmm')

            def newApkName = project + SEP + version + SEP + formattedDate + ".apk"

            output.outputFile = new File(output.outputFile.parent, newApkName)
        }
    }
}

Project build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
    }
}

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

I have just minorly edited the build.gradle from the connections app here: https://github.com/Apress/practical-android

Zain
  • 37,492
  • 7
  • 60
  • 84
CodingChap
  • 1,088
  • 2
  • 10
  • 23
  • "as it's an older project(2018)" -- it is a older than that, from the looks of the files. The build instructions date back to Android 6.0, which is about six years old now. You might consider using a newer book. – CommonsWare May 30 '21 at 20:02
  • Hmm..it was published in 2018, but maybe written earlier than that? Is there anyway I can run the project though? Thanks. – CodingChap May 30 '21 at 20:11
  • I am trying to learn about networking, and this was the most recent content I could find. – CodingChap May 30 '21 at 20:15
  • "Is there anyway I can run the project though?" -- probably, but you do not actually explain any of your problems. For example, your title has "with older dependencies", but that project has no dependencies. You might consider editing your question, deleting all but the first paragraph, and then explain exactly what your "many problems" are. Explain what you tried and explain in detail what the symptoms are. – CommonsWare May 30 '21 at 20:29
  • "I am trying to learn about networking" -- I do not know how you are defining "networking", but there are many books on Android app development that are newer than that one and demonstrate network I/O. I wrote [some of them](https://commonsware.com/catalog) myself. – CommonsWare May 30 '21 at 20:33
  • "Stuck on the loading screen devices" -- if you mean the symptoms from [this linked-to question](https://stackoverflow.com/questions/51101178/android-studio-device-list-stuck-on-loading), that should be unrelated to your project. Close the project (File < Close Project from the Android Studio main menu). From the Welcome dialog, choose "Create New Project". Use that to create some scrap project on your development machine, and see whether that drop-down works. My guess is that it will not, meaning that your problem is unrelated to that older project. – CommonsWare May 30 '21 at 20:50
  • No, it does work. If you try to open the project, are you able to run it? Thanks. – CodingChap May 30 '21 at 20:53
  • A book publication's date has little to do with how up to date it is--this, published in 2018 Apr, was likely feature-conplete months before. It targets Android API 23, current Android 11 is API 30. Even if the code itself works as-is, you will still need to fit it into recent build tools. – Dave Newton May 30 '21 at 21:16
  • Hi, how can I do that? Thanks. – CodingChap May 30 '21 at 21:18
  • I tried doing something like that using the third link, but could not find a gradle-wrapper as the writer suggested. Thanks. – CodingChap May 30 '21 at 21:22

1 Answers1

2

The most probably is that the version of the gradle build tools of these projects is not compatible with the build tools that your Android Studio supports..

So before opening any of these projects (to keep them unmodified by Android Studio), you can migrate them to the gradle version that already you've on android-studio. To do that you can use a text editor to change:

  1. In myAppName\gradle\wrapper\gradle-wrapper.properties file, in the line distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip: change to the gradle version you've (so you need to change this number in your example 6.7.1)

You can know the current gradle version(s) of Android studio from C:/Users/myUserName/.gradle/wrapper/dists/

  1. In myAppName\build.gradle you need to change the gradle plugin version to be matched with the gradle distribution version you've from step no.1. Documentation table that lists which version of Gradle is required for each version of the Android Gradle plugin.

UPDATE

Please follow below procedure.. it is tedious but works:

  1. Create a brand new project that has a package name that is the same as that of your project.

  2. Copy src, lib, raw .. or any assets folders under /app of your project into the /app of the brand new project ..

  3. Remove the themes.xml files

  4. Copy dependency from \app\build.gradle to the new project & replace compile with implementation, and testCompile with testImplementation

I did a test on one of the apps emailing app and it runs.

Zain
  • 37,492
  • 7
  • 60
  • 84
  • Hi, I have changed my dependencies by: adding google() adding mavenCentral() changing the build to 4.2.1, changing the gradle wrapper to 6.7.1, but it is still not working. Thanks. – CodingChap May 30 '21 at 22:10
  • I've also tried changing the compile sdk version to 30, and adjust the targetSdk version to 30 as well. – CodingChap May 30 '21 at 22:13
  • Hi @CodingChap it worth to share both project/module `build.gradle` contents so someone can help – Zain May 30 '21 at 22:17
  • @CodingChap Please check UPDATE section in the answer – Zain May 31 '21 at 00:56