Printooth icon indicating copy to clipboard operation
Printooth copied to clipboard

Error trying to run APP

Open andrefvneto opened this issue 2 years ago • 35 comments

Hi, since Jcenter is down i had problems trying to run my app. First it was asking about paperdb:2.6. Since i was unable to implment that library i've change my implementation of Printooth. So i updated my Printooth to 1.3.1(i am not using androix) Now it returns this error: `Execution failed for task ':app:preDebugBuild'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.android.support:design:31.0.0. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/android/support/design/31.0.0/design-31.0.0.pom - https://repo.maven.apache.org/maven2/com/android/support/design/31.0.0/design-31.0.0.pom - https://jcenter.bintray.com/com/android/support/design/31.0.0/design-31.0.0.pom - https://jitpack.io/com/android/support/design/31.0.0/design-31.0.0.pom - file:/C:/Users/myuser/.m2/repository/com/android/support/design/31.0.0/design-31.0.0.pom - https://maven.google.com/com/android/support/design/31.0.0/design-31.0.0.pom Required by: project :app Could not find com.android.support:design:31.0.0. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/android/support/design/31.0.0/design-31.0.0.pom - https://repo.maven.apache.org/maven2/com/android/support/design/31.0.0/design-31.0.0.pom - https://jcenter.bintray.com/com/android/support/design/31.0.0/design-31.0.0.pom - https://jitpack.io/com/android/support/design/31.0.0/design-31.0.0.pom - file:/C:/Users/myuser/.m2/repository/com/android/support/design/31.0.0/design-31.0.0.pom - https://maven.google.com/com/android/support/design/31.0.0/design-31.0.0.pom Required by: project :app > com.github.mazenrashed:Printooth:1.3.1

Possible solution:

  • Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html`

Couldn't find nothing online about com.android.support:design:31.0.0. Any suggestions? I'm really trying not to update to androidx, Thanks

andrefvneto avatar May 12 '22 11:05 andrefvneto

did you find the solution?

GithubPranshul avatar Sep 08 '22 08:09 GithubPranshul

Hi, i belive it was this line that i had to change implementation 'com.github.mazenrashed:Printooth:1.2.1'

About paperdb i found a project (Paper-2.6) and i belive that i've imported the libraries directly into my project. It was some time ago.. sorry

andrefvneto avatar Sep 08 '22 09:09 andrefvneto

oh, ok no problem thank you!

GithubPranshul avatar Sep 08 '22 10:09 GithubPranshul

Hi, I ran into the same issue now and I just can't fix it. I get the same error message and have no idea why. Could you please give me a hint or some idea on how to fix this? Thanks!

matej-dostal avatar Nov 29 '22 14:11 matej-dostal

Hi, can you please post the error/log? Thanks

andrefvneto avatar Nov 29 '22 14:11 andrefvneto

Sure, here it is, this is logged when I try to build the app:

Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find com.android.support:design:31.0.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/support/design/31.0.0/design-31.0.0.pom
       - https://repo.maven.apache.org/maven2/com/android/support/design/31.0.0/design-31.0.0.pom
       - https://jitpack.io/com/android/support/design/31.0.0/design-31.0.0.pom
       - https://jcenter.bintray.com/com/android/support/design/31.0.0/design-31.0.0.pom
     Required by:
         project :app > com.github.mazenrashed:Printooth:1.3.1

and it fails for these tasks (the error message is the exact same for each of them):

Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'.
Execution failed for task ':app:mergeDebugResources'.
Execution failed for task ':app:checkDebugAarMetadata'.
Execution failed for task ':app:mapDebugSourceSetPaths'.
Execution failed for task ':app:processDebugMainManifest'.
Execution failed for task ':app:mergeDebugAssets'.
Execution failed for task ':app:checkDebugDuplicateClasses'.
Execution failed for task ':app:desugarDebugFileDependencies'.
Execution failed for task ':app:mergeDebugNativeLibs'.

matej-dostal avatar Nov 29 '22 14:11 matej-dostal

I have it like this: `repositories { mavenLocal() google() mavenCentral() maven { url 'https://www.jitpack.io' } maven { url "https://maven.google.com/" } jcenter()

}Dependecies: implementation 'com.github.mazenrashed:Printooth:1.2.1'`

andrefvneto avatar Nov 29 '22 15:11 andrefvneto

When I use 1.2.1 version and have it like you do, manifest merger fails, because the rest of the app supports androidx, whereas v1.2.1 doesn't. So when I use v1.3.1 of Printooth, the same errors shows up again as I posted earlier.

matej-dostal avatar Nov 29 '22 17:11 matej-dostal

@matej-dostal Hi did you fix the error? Even I am facing the same issue, can you please share the solution if you have got it

gaara40 avatar Apr 26 '23 12:04 gaara40

@matej-dostal Hi did you fix the error? Even I am facing the same issue, can you please share the solution if you have got it

Hi! I did fix it, but to be honest I don't remember exactly how. Could you share both your build.gradle files as well as settings.gradle? It was in one of those files that fixed it so I will have a look at it :)

matej-dostal avatar Apr 26 '23 13:04 matej-dostal

@matej-dostal Sure, build.gradle files(project level) -- // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '7.3.1' apply false id 'com.android.library' version '7.3.1' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false }

build.grade(Module) -- plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' }

android { namespace 'com.gaara.thermalprint' compileSdk 33

defaultConfig {
    applicationId "com.gaara.thermalprint"
    minSdk 28
    targetSdk 33
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

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

}

dependencies {

implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'com.github.mazenrashed:Printooth:1.3.1'
implementation 'com.github.kenglxn.QRGen:android:2.6.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

}

settings.gradle -- pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url 'https://jitpack.io' } maven { url "https://maven.google.com/" } } } rootProject.name = "ThermalPrint" include ':app' ..........................

since, jcenter() is deprecated android studio suggests to use mavenCentral() only

gaara40 avatar Apr 26 '23 14:04 gaara40

@matej-dostal Sure, build.gradle files(project level) -- // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '7.3.1' apply false id 'com.android.library' version '7.3.1' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false }

build.grade(Module) -- plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' }

android { namespace 'com.gaara.thermalprint' compileSdk 33

defaultConfig {
    applicationId "com.gaara.thermalprint"
    minSdk 28
    targetSdk 33
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

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

}

dependencies {

implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'com.github.mazenrashed:Printooth:1.3.1'
implementation 'com.github.kenglxn.QRGen:android:2.6.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

}

settings.gradle -- pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url 'https://jitpack.io' } maven { url "https://maven.google.com/" } } } rootProject.name = "ThermalPrint" include ':app' ..........................

since, jcenter() is deprecated android studio suggests to use mavenCentral() only

Okay, so the only difference that I found when compared with my .gradle files is in kotlinOptions, I have it like this: kotlinOptions { jvmTarget = '1.8' freeCompilerArgs += [ '-Xjvm-default=enable' ] }. So give it a try and let me know if that wasn't the solution, I'll keep looking :)

matej-dostal avatar Apr 26 '23 14:04 matej-dostal

@matej-dostal I'm still getting the same error even after adding the above line of code in the kotlinOptions, can you please help me solve this further

gaara40 avatar Apr 26 '23 18:04 gaara40

@matej-dostal I'm still getting the same error even after adding the above line of code in the kotlinOptions, can you please help me solve this further

I just realised one more thing, could you post gradle.properties as well, please?

matej-dostal avatar Apr 26 '23 18:04 matej-dostal

Yeah, sure here is the gradlde.properties file

Project-wide Gradle settings.

IDE (e.g. Android Studio) users:

Gradle settings configured through the IDE will override

any settings specified in this file.

For more details on how to configure your build environment visit

http://www.gradle.org/docs/current/userguide/build_environment.html

Specifies the JVM arguments used for the daemon process.

The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

When configured, Gradle will run in incubating parallel mode.

This option should only be used with decoupled projects. More details, visit

http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects

org.gradle.parallel=true

AndroidX package structure to make it clearer which packages are bundled with the

Android operating system, and which are packaged with your app's APK

https://developer.android.com/topic/libraries/support-library/androidx-rn

android.useAndroidX=true

Kotlin code style for this project: "official" or "obsolete":

kotlin.code.style=official

Enables namespacing of each library's R class so that its R class includes only the

resources declared in the library itself and none from the library's dependencies,

thereby reducing the size of the R class for that library

android.nonTransitiveRClass=true

gaara40 avatar Apr 26 '23 19:04 gaara40

gaara40

good, try adding android.enableJetifier=true

matej-dostal avatar Apr 26 '23 20:04 matej-dostal

class MainActivity : AppCompatActivity() {

private var printing: Printing? = null
lateinit var btnPrint: Button
lateinit var etName: EditText

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    if (Printooth.hasPairedPrinter())
        printing = Printooth.printer()
    setContentView(R.layout.activity_main)

    btnPrint = findViewById(R.id.btnPrint)
    etName = findViewById(R.id.etName)

    initListeners()
}

private fun initListeners() {
    btnPrint.setOnClickListener {

        if (!Printooth.hasPairedPrinter())
            resultLauncher.launch(
                Intent(
                    this@MainActivity,
                    ScanningActivity::class.java
                ),
            )
        else printDetails()
    }

    printing?.printingCallback = object : PrintingCallback {
        override fun connectingWithPrinter() {
            Toast.makeText(this@MainActivity, "Connecting with printer", Toast.LENGTH_SHORT)
                .show()
        }

        override fun printingOrderSentSuccessfully() {
            Toast.makeText(this@MainActivity, "Order sent to printer", Toast.LENGTH_SHORT)
                .show()
        }

        override fun connectionFailed(error: String) {
            Toast.makeText(this@MainActivity, "Failed to connect printer", Toast.LENGTH_SHORT)
                .show()
        }

        override fun onError(error: String) {
            Toast.makeText(this@MainActivity, error, Toast.LENGTH_SHORT).show()
        }

        override fun onMessage(message: String) {
            Toast.makeText(this@MainActivity, "Message: $message", Toast.LENGTH_SHORT).show()
        }

        override fun disconnected() {
            Toast.makeText(this@MainActivity, "Disconnected Printer", Toast.LENGTH_SHORT).show()
        }
    }
}

private fun printDetails() {
    val printables = ArrayList<Printable>()
    val printable = TextPrintable.Builder()
        .setText("Hello World")
        .build()
    printables.add(printable)
    Printooth.printer().print(printables)
}

/*private fun getSomePrintables() = ArrayList<Printable>().apply {

    add(RawPrintable.Builder(byteArrayOf(27, 100, 4)).build()) // feed lines example in raw mode
    add(
        TextPrintable.Builder()
            .setText("Hello World")
            .setLineSpacing(DefaultPrinter.LINE_SPACING_60)
            .setAlignment(DefaultPrinter.ALIGNMENT_CENTER)
            .setFontSize(DefaultPrinter.FONT_SIZE_LARGE)
            .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_BOLD)
            .setUnderlined(DefaultPrinter.UNDERLINED_MODE_OFF)
            .setNewLinesAfter(1)
            .build())
}*/

var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
    if (result.resultCode == ScanningActivity.SCANNING_FOR_PRINTER &&  result.resultCode == Activity.RESULT_OK) {
        // There are no request codes

// val intent = result.data printDetails() } } } this is my code now I can run the app, but I after I click the print button, I am being shown the scanning activity but there is nothing on the page, please guide me where I am going wrong

WhatsApp Image 2023-04-27 at 1 25 32 PM (1)

gaara40 avatar Apr 27 '23 07:04 gaara40

@gaara40 do you have bluetooth on your device turned on, your bluetooth printer turned on and paired with the device?

matej-dostal avatar Apr 27 '23 08:04 matej-dostal

yes the bluetooth printer is turned on and is paired to my android device and the Bluetooth is also turned on in my android device

gaara40 avatar Apr 27 '23 08:04 gaara40

yes the bluetooth printer is turned on and is paired to my android device and the Bluetooth is also turned on in my android device

And does your app have required permissions from user given in runtime? Without that I think you won't make it work.

matej-dostal avatar Apr 27 '23 08:04 matej-dostal

yes, the permissions are also granted

gaara40 avatar Apr 27 '23 08:04 gaara40

I have these permissions required in runtime (also specified in manifest) and it works fine:

  • Manifest.permission.BLUETOOTH_SCAN (in manifest I have additional flag neverForLocation)
  • Manifest.permission.BLUETOOTH_CONNECT
  • Manifest.permission.BLUETOOTH_ADMIN

matej-dostal avatar Apr 27 '23 08:04 matej-dostal

I had these permissions in manifest, I figured out the code now and it worked thankyou so much @matej-dostal for helping me out. There is something more I need to know, can we print custom texts like if we enter a name or a number in the edittext fields and click the print button the name and the number gets printed?

gaara40 avatar Apr 27 '23 08:04 gaara40

I had these permissions in manifest, I figured out the code now and it worked thankyou so much @matej-dostal for helping me out. There is something more I need to know, can we print custom texts like if we enter a name or a number in the edittext fields and click the print button the name and the number gets printed?

No problem, I'm happy to help :) Sure thing we can, just build the printable, you send to the printer, dynamically and fill it with the input from user :)

matej-dostal avatar Apr 27 '23 08:04 matej-dostal

Got it, Thank you very much @matej-dostal for your guidance, I don't know where would I be without your help, I am trying this since 3 weeks, finally got it done.

gaara40 avatar Apr 27 '23 08:04 gaara40

No problem, good luck coding the rest of the app :) @gaara40

matej-dostal avatar Apr 27 '23 08:04 matej-dostal

my app runs only when i explicitly allow the nearby devices permission, otherwise the app crashes when I click the print button, any solutions??? tried the onrequestpermission but still not working.....

gaara40 avatar May 26 '23 07:05 gaara40

Hi, can you try this: Since android 12, you need to runtime ask for the permission if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {

        // Caso a permissão ainda não tenha sido concedida, solicita ao usuário
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.BLUETOOTH_CONNECT},
                4444);
    } else{
        //has permisson, your code logic

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, 1);

        }
    }

@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 4444) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // GRANTED } else { //DECLINED } } }

Dont forget to add to the manifest "BLUETOOTH_CONNECT" permission

andrefvneto avatar May 26 '23 09:05 andrefvneto

still not working

gaara40 avatar May 26 '23 12:05 gaara40

can you give more detail? when the app crashes what kind of error it returns?

andrefvneto avatar May 26 '23 13:05 andrefvneto