AndroidStudio was not right after change code - android

Situation:
I use Android studio, when i change a line of code in it sometimes it was wrong, the code i just change is not work it still run my old version code.
such as
int a = 1;//old version
int a = 2;//new version
sometimes a still value 1 when i run the new version code.
fix:
I know i can clean the project and restart Android Studio to fix it, but why it's happened?
My Question:
It's just a AS bug or something i was wrong in my project setting?
For more detail example:
I have class a with the method putLog() like below
private void putLog()
{
Log.i("tag","string");
}
Then i find i don't need the Log.i("tag","string") anymore, so i delete it
private void putLog()
{
// Log.i("tag","string");
}
but after i delete it, the log output is still there, my delete is not work.
I restart Android Studio and clean the cache, the log is not show anymore.

That's mainly because i have use multiple-channel gradle script to generate apk, now i remove it, it not show again.

Related

android NDK : cannot find execution point

I'm debugging my Android app in Android Studio, and it failed to find execution point of native code, as a result, variables also cannot be shown:
World::flush looks like this:
void World::flush() {
LOGE_LS("Flushing cached chunks...");
for (chunk_lru_li *i = lru, *j; i != nullptr; i = j) {
if (i->item->flag == CHUNK_LI_DIRTY) {
LOGE_LS("Saving chunk (%d,%d).", i->item->key.x_div16, i->item->key.z_div16);
i->item->val->save();
LOGE_LS("Saved chunk.");
}
j = i->next;
delete i->item->val;
delete i->item;
delete i;
}
lru = nullptr;
mru = nullptr;
num_chunks = 0;
memset(chunks, 0, sizeof(chunks));
LOGE_LS("Flusing done.");
}
Debugger type was set to Native.
Threads and call stack are displayed.
This used to work several months ago within the same project.
Release version of a shared library was used but does not seems to be the reason.
I tried many variables of different functions in the call stack, not only the lru in screenshot.
Build variants of all modules are debug (Otherwise the app won't be debuggable at all)
Thanks meow~
Solved by searching on CSDN blog:
Find your module that contains c/c++ code, open its iml file on the Project panel:
find this tag: <facet type="native-android-gradle" name="Native-Android-Gradle">
under the tag find <option name="SELECTED_BUILD_VARIANT" value="release" />
change release to debug. If it's already debug then it seems not the reason to your problem.
Save & Close the file then do Gradle sync.
It should be fixed now. If not, clean build may or may not help.
Link of original answer at CSDN blog: https://blog.csdn.net/wangyun522/article/details/78820569
It's not in English and you may not want to check it out.

More than one file was found with OS independent path 'kotlin/reflect/reflect.kotlin_builtins' - Unity Project

I was trying to create Android build after exporting from Unity Project.
When I tried to export signed APK file, I got many errors and step by step , I have cleared all others.
But at present, get stuck on this one :
This is my Gradle file content :
I have tried Stackoverflow posts with similar problems. So I expect some other solution that work for me.
It seem it's an old post , but i m writing down here a solution it may help somebody else to solve this issue
In your app gradle (Kotlin DSL), add this block :
android {
//...
packagingOptions {
exclude("META-INF/kotlin-stdlib-common.kotlin_module")
exclude("META-INF/kotlin-stdlib-jdk7.kotlin_module")
exclude("META-INF/kotlin-stdlib-jdk8.kotlin_module")
exclude("META-INF/kotlin-stdlib.kotlin_module")
exclude("kotlin/annotation/annotation.kotlin_builtins")
exclude("kotlin/collections/collections.kotlin_builtins")
exclude("kotlin/coroutines/coroutines.kotlin_builtins")
exclude("kotlin/internal/internal.kotlin_builtins")
exclude("kotlin/kotlin.kotlin_builtins")
exclude("kotlin/ranges/ranges.kotlin_builtins")
exclude("kotlin/reflect/reflect.kotlin_builtins")
}
// ....
}
This will fix the build error.

Getting the Android SDK directory within a gradle task

Recently the gradle plugin for android got updated (with android studio), after which the previous way of getting to the SDK directory ceased to work. The expression
${android.plugin.sdkDirectory}
which worked in an older version now returns the error
Error:(42, 0) No such property: sdkDirectory for class: com.android.build.gradle.LibraryPlugin
What would be the proper way of getting the android SDK directory being used, preferably independent of the user's configuration such as plugin and gradle version? The script needs to be shareable with several users.
Since all the previous answers depend on the environment or specific user intervention on top of normal configuration, I'll just post my technically messy fix.
if (android.hasProperty('plugin')) {
if (android.plugin.hasProperty('sdkHandler')) {
androidPath = android.plugin.sdkHandler.sdkFolder
} else {
androidPath = android.plugin.sdkDirectory
}
} else {
androidPath = android.sdkDirectory
}
Unlike all previous methods, this actually works, but it still looks hacky.
In gradle.properties set location sdkdir=/home/user/android-sdk and then in gradle you can use $sdkdir
I'm using Android gradle plugin v1.2.3 and this works fine:
${android.sdkDirectory}
You can use
$System.env.ANDROID_HOME
export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.

Android Nullpointerexception thrown when R.id value not found

When I add a new activity (.java and .XML files) in my Android Project some R.id values that used to work get lost and causes my App to throw a NullPointerException, but if I use the hex value it works again:
R.java: public static final int editTextTotal=0x7f040064;
findViewById(R.id.editTextTotal); //Throws nullpointerex after I add a new activity.
findViewById(0x7f040067) //Works
I got tired of Eclipse so I'm working with commands only, is there anything else that should be done other than add the files, change the manifest and run the "ant debug" command to add new activities?
What is the import your are using? You have to use
your_package_name.R
There is something wrong with your ADT. Try to update to the latest version.
If the problem still exists, try to clean the project whenever you add a new xml.

Unable to run Bitmap sample code for Android

I am trying to run the sample from :
http://developer.android.com/training/displaying-bitmaps/display-bitmap.html
However I encountered lots of errors like:
Description Resource Path Location Type
BuildConfig cannot be resolved to a variable ImageGridFragment.java /ImageGridActivity/src/com/example/android/bitmapfun/ui line 124 Java Problem
Description Resource Path Location Type
SuppressLint cannot be resolved to a type Utils.java /ImageGridActivity/src/com/example/android/bitmapfun/util line 99 Java Problem
I ran thru Google but could get nothing. Adjusted the android build target to 4.0.3 (15) but still no clue. Anyone ran this sample successfully?
Thanks.
Here is my solution:
1.Create a new class:
package com.example.android.bitmapfun;
public class BuildConfig {
public static final boolean DEBUG = true;
}
2.Comment the lines that contain "SuppressLint":
//import android.annotation.SuppressLint;
// #SuppressLint("NewApi")
Android developer tools r17 brings a feature to Eclipse where a class is auto built at build-time, called BuildConfig, which contains a constant that can be used by the app developer to sense whether the build is a dev build or a production build. This feature appears to be in the Eclipse integration support, so when using IntelliJ, this useful feature is not available
In gen folder with R.java there should be BuildConfig.java if your program compiled successfully.
/** Automatically generated file. DO NOT MODIFY */
package com.example.android.bitmapfun;
public final class BuildConfig {
public final static boolean DEBUG = true;
}
Clean your project and try to launch it again.
It worked for me.
For me also it is not running directly import to eclipse. Just i put comments which lines is showing errors then it is working fine for me. May be it is not a right answer but we can see the application functionality by running the code so i did like that.

Categories

Resources