Printooth
Printooth copied to clipboard
Error trying to run APP
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
did you find the solution?
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
oh, ok no problem thank you!
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!
Hi, can you please post the error/log? Thanks
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'.
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'`
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 Hi did you fix the error? Even I am facing the same issue, can you please share the solution if you have got it
@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 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
@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 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
@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?
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
good, try adding android.enableJetifier=true
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
@gaara40 do you have bluetooth on your device turned on, your bluetooth printer turned on and paired with the device?
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
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.
yes, the permissions are also granted
I have these permissions required in runtime (also specified in manifest) and it works fine:
-
Manifest.permission.BLUETOOTH_SCAN
(in manifest I have additional flagneverForLocation
) -
Manifest.permission.BLUETOOTH_CONNECT
-
Manifest.permission.BLUETOOTH_ADMIN
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?
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 :)
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.
No problem, good luck coding the rest of the app :) @gaara40
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.....
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
still not working
can you give more detail? when the app crashes what kind of error it returns?