I am trying to debug native (C/C++) code inside my Android project but the breakpoints are not hitting. Tried many proposed solutions like here, here, here, here and a few others I saw but no success.
Debugging normal Java code works fine, stops on set breakpoints as expected. However when setting breakpoints on the C/C++ code, it says after launching, that it didn't find any line of code respective to that breakpoint so it won't be hit.
What I found mostly funny is, if I hit a breakpoint right after going into the native code, and then stepping in, it not only goes in, but also allows me at that point to then set breakpoints on the native code. So it seems it is not loading the native libs during debugging somehow I guess... and after I force to step in from the Java into native, he then enables something and then I am able to set new breakpoints on the native code and they hit as expected. Am I missing any silly configuration?
I am using Android Studio Electric Eel 2022 (up-to-date), NDK and SDK version can be found below.
Here is my build.gradle from project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and my build.gradle from the app:
apply plugin: 'com.android.application'
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
android {
signingConfigs {
release {
}
}
compileSdkVersion 33
buildToolsVersion '33.0.1'
defaultConfig {
applicationId "com.local.projeto"
minSdkVersion 26
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
debuggable true
renderscriptDebuggable true
minifyEnabled false
}
}
externalNativeBuild {
ndkBuild {
path file('src/main/jni/Android.mk')
}
}
ndkVersion '25.1.8937393'
dependenciesInfo {
includeInApk true
includeInBundle true
}
}
dependencies {
debugImplementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains:annotations-java5:15.0'
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
my proguard rules have (which made no difference changing this):
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
I also tried to add the Symbols Folder manually on the Debug configuration, but also no success. And it does not seem to be a problem at all on the symbols and compilation, as it is possible to debug the native code. It seems to be just a matter of initialization when debugging. Any ideas?
Related
I'm implementing my android-module from github using jitpack,
and i want to do compileOnly instead of implementation
but when I use the code compileOnly it shows me
that the complieOnly not supported
I'm creating an application to read plugins
all application and plugins depends on a library I have created
the plugin well have a classes that extends a class on the library
and the application should read those classes and invoke methods on them
as you know the application SHOULD contains the library classes
and the plugin SHOULDN'T, else we'll face a doublecated classes exception or/and class cast exception
I worked on it and it worked perfectly while the application and
the plugins all compiled the library using an aar file of it
but when i decied to move on to github implementation
it worked for the application but not for the plugin
and the issue is i can't tell gradle to do compileOnly to the library
plugin's module build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 24
targetSdkVersion 29
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 = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
compileOnly 'com.github.LSaferSE:Services-Android:master'//<--- here is the problem
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
}
plugin's project build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
expecting a build success but faced :
ERROR: Android dependency 'com.github.LSaferSE:Services-Android:master' is set to compileOnly/provided which is not supported
one more thing, I tried using api instead but I'm not sure what's the diffrent from implementation, but I'm sure it'll pack library classes in the plugin's apk, so please tell me if you know it'll not effect while loading the apk using DexClassLoader (fyi it'll effect using implementation)
This is so frustrating and confusing! If anyone can help me understand what's wrong, I'd greatly appreciate it!
I'm building a Unity app, and per the directions from ironSource, I have to use a custom gradle template so I can set a couple of flags or whatever.
1. This is my Android Studio version:
2. This is the error I get when attempting to build in Unity:
3. This is the edited gradle-wrapper.properties file with 5.1.1-all set:
4. This is my mainTemplate.gradle
buildscript
{
repositories
{
google()
jcenter()
}
dependencies
{
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
allprojects
{
repositories
{
google()
jcenter()
flatDir
{
dirs 'libs'
}
}
}
apply plugin: 'com.android.application'
dependencies
{
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0'
implementation 'com.android.support:support-v4:27.1.1'
**DEPS**
implementation 'com.google.android.gms:play-services-ads:17.2.0'
}
android
{
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
defaultConfig
{
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
}
lintOptions
{
abortOnError false
}
aaptOptions
{
noCompress '.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**
}
**SIGN**
buildTypes
{
debug
{
minifyEnabled **MINIFY_DEBUG**
useProguard **PROGUARD_DEBUG**
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
jniDebuggable true
}
release
{
minifyEnabled **MINIFY_RELEASE**
useProguard **PROGUARD_RELEASE**
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'**USER_PROGUARD**
**SIGNCONFIG**
}
}
}
If anyone knows how to fix this, please share! I've ready through all of the similar problems here on SO, but none of the supposed solutions work. I keep changing version numbers all over the place, and still, errors.
On top of that, my Unity CloudBuild also fails, with similar problems. I don't have control over what versions they have, so I can't even begin to plan on how to fix that.
Please help!! and thank you sincerely!
-Matt
I developed an app that uses a swagger-generated Java client. The client is in a project called "api", while the app is in a project called "app".
When I build the app via Build/Make Project everything works fine. Also, when I try to run the app on an emulated or physical device Run/Run 'app'. Running with debugger works as well. Even when I build the project via Buid/Generate Signed Bundle/APK and choose the debug option, it works.
Now. The build fails when I try to create a signed release build. The following messages show:
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: [...]\app\build\intermediates\transforms\dexBuilder\release\54, [...]\app\build\intermediates\transforms\externalLibsDexMerger\release\0, [...]\app\build\intermediates\transforms\dexBuilder\release\52.jar, [...]\app\build\intermediates\transforms\dexBuilder\release\53.jar
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: [...]\app\build\intermediates\transforms\dexBuilder\release\54, [...]\app\build\intermediates\transforms\externalLibsDexMerger\release\0, [...]\app\build\intermediates\transforms\dexBuilder\release\52.jar, [...]\app\build\intermediates\transforms\dexBuilder\release\53.jar
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: io.swagger.client.ApiCallback
I am pretty new to developing with Android Studio and Gradle. I tried some solutions on Stack Overflow that already suggested to add some libraries but so far none of them worked with my problem.
To me, its especially suspicious that the last error message points to io.swagger.client.ApiCallback.
Could it have anything to do with the fact that both settings.gradle for "api" and "app" have the same content? Both look like this:
rootProject.name = "swagger-java-client". This is the only line in the file, but as far as I know, the settings.gradle for "app" already hat that content. I cant remember changing it so its odd to me that it shows "swagger-java-client". Is that normal?
Update 1
ProGuard has been mentioned in the comments to might be a problem. This is the only occurrence I could find, referencing it. In my build.gradle for the "app"-project, there is this part:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
However, removing it did not change anything.
Update 2
When searching for "io.swagger" AS only finds this:
When searhing for "io.swagger.client.ApiCallback" AS only finds this:
Update 3
As suggested, I tried adding
android {
defaultConfig {
multiDexEnabled true
}
}
and adding android.enableD8 = false but that didn't help either.
Here are my build.gradle-Files (the first ones that caused the problems, without the suggested corrections I've tried so far.)
build.gradle (Module: api) (generated by Swagger):
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
dependencies {
provided 'javax.annotation:jsr250-api:1.0'
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-java-client'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
dependencies {
compile 'io.swagger:swagger-annotations:1.5.21'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
compile 'com.google.code.gson:gson:2.8.2'
compile 'org.threeten:threetenbp:1.3.5'
testCompile 'junit:junit:4.12'
}
build.gradle (Module: app):
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "projectName"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "0.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation fileTree(dir: '../api/build/libs', include: ['*.jar'])
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
api project(path: ':api')
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'org.jetbrains:annotations-java5:15.0'
}
Here are some workaround :
Can you please make sure you have multiDexEnabled set to true as shown below in your gradle settings:
android {
defaultConfig {
multiDexEnabled true
}
}
Try android.enableD8 = false in grade.properties
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: io.swagger.client.ApiCallback
Means there are multiple dependencies contain this class, maybe different versions, so you need to exclude them.
Press shift twice, search io.swagger, then record the found jar files.
If these jar files are simply duplicated, keep 1 in build.gradle.
If these jar files are modules of other dependency, enter gradlew -q app:dependencies in the terminal, find the root dependency names.
In build.gradle, choose 1 dependency to keep, for others add exclude command.
For example change
implementation 'xxx:xxx'
to
implementation ('xxx:xxx') { exclude module 'module-name-to-be-excluded' }
UPDATE
Some options to try:
Change build variants of both modules to release, then Build\Build APK
If success, copy the text from Gradle Console.
Next Build\Generate Signed APK...
Compare the text in Gradle Console with the above one to check the difference.
I've found the answer to my question:
What I did was to create the swagger client, move the created folder into my project, adjust the settings.gradle file and the build.gradle file accordingly.
What went wrong
The way I configured things, gradle would build the ´api´ project and then the app project.
For some reason, when I configured things as release, the app project referenced the code of the api project, as well as the resulting .jar file. Thats where the Program type already present came from.
How I fixed it
Exclude the api project from the app project
Build api seperately
Take the resulting .jarfile and put it in a folder inside your app folder called libs
Put this line in your gradle dependencies for your build.gradle (Module: app): implementation fileTree(dir: 'libs', include: ['*.jar'])
This included the finished .jarfile in the appproject and now I can build release. This should be done regardless, because the swagger client shouldnt be edited anyway, as it is generated code. So even just to not always build that part of the project, this should be done.
However, I still dont fully understand why there is this difference between the releaseand the debugbuild. Would be glad for any insight to that.
EDIT: ADDITIONAL INFORMATION
I just found out: if, for some reason, I would have wanted to keep the Module: api in my project I could have done so by removing the two dependencies in my Module: appthat start with implementation fileTree.
The api-project is already included by the dependency api project(path: ':api'). The filetree-lines were the ones causing the problem here, since they were redundant.
However, still no idea why there is a difference between debug and release
I am using AS 3.1 with gradle-4.5-all.zip and main build.gradle:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
An app-level build.gradle looks like following:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 27
versionCode 6
versionName "1.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'ch.acra:acra:4.6.1'
implementation 'commons-validator:commons-validator:1.5.0'
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.google.zxing:core:3.3.0'
}
and works fine when I set up a debug version under AS 3.1 to my phone, but when I try to make release apk it shows me an error:
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build
script as follows:
...
android {
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
}
}
As I can see in the lint-results-release-fatal.html the reason is:
I would not like to change lintOptions to supress this error because it doesn't solve the problem, it just hide it. More over, when I use
implementation files('libs/commons-validator-1.5.0.jar')
instead of
implementation 'commons-validator:commons-validator:1.5.0'
the release apk is compiled without any error messages. Is it a some gradle bug or what!?
P.S. I have attached a file androidDependencies.txt. Package commons-logging doesn't appears in the dependencies at all! How is it possible to get the solution of above problem analysing this file?
the release apk is compiled without any error messages. Is it a some
gradle bug or what!?
It seems like that dependency has a package which conflicts with the Android itself. The reason why it works without implementation and adding it manually, it might be that it downloads needed packages when you add it to be downloaded from maven repository and that's when the issue came up.
Anyways, the solution at these situations might be using the latest version:
implementation 'commons-validator:commons-validator:1.6'
Or, exclude it as follows:
implementation ('commons-validator:commons-validator:1.5.0') {
exclude group: 'commons-logging', module: 'commons-logging'
}
Note: The following part can't be helpful (for this issue) since the error says:
Commons-logging defines classes that conflict with classes now
provided by Android
You could go deeply by running ./gradlew app:dependencies in the IDE terminal to see which one conflicts with the Android itself and then excluding it as above.
I have a C++ library built for Android, which I package as an Android archive (.aar), along with some Java classes and a Manifest.
Everything is done outside of Android Studio. To package the .aar, I have a directory that contains:
app/src/main/jniLibs/arm64-v8a/: directory with library
app/src/main/java: directory with Java classes
The directory also contains the manifest, and Gradle files.
Here is the build.gradle in the app directory:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.0.2'
}
apply plugin: 'maven-publish'
publishing {
publications {
fooapp(MavenPublication) {
groupId 'com.example'
artifactId 'fooapp'
version "develop"
artifact('build/outputs/aar/app-release.aar')
}
}
repositories {
maven {
mavenLocal()
}
}
}
publishToMavenLocal.dependsOn assemble
By default, all the AAR files contain a stripped version of the library. I do not want the library to be stripped when assembling the Debug version of the AAR.
I found out that I can use packagingOptions to disable stripping, so I tried to add packagingOptions { doNotStrip "**/*/*.so" } under the debug {...} scope of the configuration file.
My problem is that both the debug and release versions of the AAR are then stripped. The two versions of the AAR do seem different, since they don't have the same size (hence have different md5sum).
Where/how can I place my packagingOptions in the Gradle configuration file so that only the release version is stripped? Thanks
The packaging options are specified under buildTypes and then the configuration like Debug or Release etc.
Example:
buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so'
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
packagingOptions {
doNotStrip '**/*.so'
}
}
}
Note: you added an extra directory /*/ in your specified path.