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.
Related
Unity has a default gradle.properties file that gets added during the build process. While its possible to change the build.gradle and the settings.gradle files as mentioned
here https://docs.unity3d.com/Manual/android-gradle-overview.html
there is no mention of being able to change gradle.properties within the unity docs. The file also gets recreated every build attempt so editing it within the temp/gradleOut after a build and building again doesn't work. I know exporting the project is possible as well, but I'm looking for a solution where the project can be run directly from unity.
Btw this question is NOT a duplicate of this question How to use Gradle in Unity
The answer here has nothing to do with modifying the gradle.properties file.
This is a duplicate of this question that got incorrectly marked as a duplicate how to change default gradle.properties of Unity?
Maybe my answer is a bit outdated but in Unity 2020 you can do it in:
Player Settings -> Tab Android (with robot obviously) -> Publishing Settings -> Custom Gradle Properties Template (checkbox).
After enabling the checkbox you will see the path to gradleTemplate.properties (usually it appears in Assets/Plugins/Android directory) file which will be merged with final gradle.properties.
Everything you need you can write to the end of file after **ADDITIONAL_PROPERTIES** string.
Example:
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
android.enableR8=**MINIFY_WITH_R_EIGHT**
**ADDITIONAL_PROPERTIES**
android.useAndroidX = true // I added this property to fix error: This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
Also on screenshot:
This was something that was slightly hard to discover. I was going to do a regular post build processor like I had for my iOS build, but as I was searching for a manner to load and determine where the properties file was, I ran across the following interface in the documentation : IPostGenerateGradleAndroidProject.
According to the documentation:
Implement this interface to receive a callback after the Android
Gradle project is generated.
So below is my initial brute force implementation for turning on androidX and jetifier.
public class AndroidPostBuildProcessor : IPostGenerateGradleAndroidProject
{
public int callbackOrder
{
get
{
return 999;
}
}
void IPostGenerateGradleAndroidProject.OnPostGenerateGradleAndroidProject(string path)
{
Debug.Log("Bulid path : " + path);
string gradlePropertiesFile = path + "/gradle.properties";
if (File.Exists(gradlePropertiesFile))
{
File.Delete(gradlePropertiesFile);
}
StreamWriter writer = File.CreateText(gradlePropertiesFile);
writer.WriteLine("org.gradle.jvmargs=-Xmx4096M");
writer.WriteLine("android.useAndroidX=true");
writer.WriteLine("android.enableJetifier=true");
writer.Flush();
writer.Close();
}
}
Theoretically you should be able to manipulate the generated gradle project in any manner to your choosing during the post build processor. Some additional tools might be helpful, like the PBXProject support on iOS, but until then, this will do.
IPostGenerateGradleAndroidProject is a new Interface added after Unity2018.
As my project based on Unity2017, it's not a good solution. Then I found this. A solution with Gradle.
([rootProject] + (rootProject.subprojects as List)).each {
ext {
it.setProperty("android.useAndroidX", true)
it.setProperty("android.enableJetifier", true)
}
}
Although this is not a perfect solution, you can use the "Export Project" option.
Build Settings
After exporting the project, you can modify gradle.properties and build using AndroidStudio or command line.
In the newer Unity versions (2019.4+) it is possible to generate a custom gradle properties template by going to Project Settings > Player > (Android Tab) > Other Settings > and marking "Custom Gradle Properties Template".
After selecting that a gradleTemplate.properties file is generated at "Assets/Plugins/Android/gradleTemplate.properties".
This is the best way of generating the file since it is git friendly and preserves other settings.
About Bintray-release plugin
I am using bintray-release to upload my library to maven.Its doc says how to use it:
Use the publish closure to set the info of your package:
publish {
userOrg = 'novoda'
groupId = 'com.novoda'
artifactId = 'bintray-release'
publishVersion = '0.3.4'
desc = 'Oh hi, this is a nice description for a project, right?'
website = 'https://github.com/novoda/bintray-release'
}
Finally, use the task bintrayUpload to publish
$ ./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
In my case
Then I define my publish closure:
publish {
groupId = 'com.uniquestudio'
artifactId = 'parsingplayer'
publishVersion = '2.0.6'
website = 'https://github.com/TedaLIEz/ParsingPlayer'
Properties properties = new Properties()
InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream() ;
properties.load( inputStream )
bintrayUser = properties.getProperty('bintrayUser')
bintrayKey = properties.getProperty('bintrayKey')
}
As you can see,out of safety I put bintrayUser and bintrayKey into local.properties.
My Question
First
I know I can put bintrayUser and bintrayKey in loacal.properties and gradle.properties.Is there any other way to store private data while I don't think is't suitable to store private data within current project ?
Second
Everything is ok but when I push my project to CI.I get error:
/home/travis/build/TedaLIEz/ParsingPlayer/local.properties (No such file or directory)
So I want to know How gradle task deal with extension objects,in my case,publish object.Is there any way to fix it?
First, I have to tell you that it is not recommended to ask two questions at once via StackOverflow, mainly because it may be hard to choose a correct answer, if two answers help you with the different questions you asked.
Anyhow, I'll try to answer both of your questions:
First
To use an additional properties file (local.properties in your case) is not a Gradle approach. It is in fact pure Java. You should only read properties on your own in very rare cases and never in a build script. If you really need an additional properties file, develop a Gradle plugin, which handles the file access.
Gradle automatically reads the gradle.properties file, but not only in the project directory, but also in the user-specific gradle home directory (e.g. C:\Users\*<User>*\.gradle). This is helpful to define private data, which won't find its way into version control, even if you forget to ignore the files manually. The defined data will be accessible to any project.
Second
Well, I assume the file local.properties does not exist, because you did neither put it under version control nor let your CI add it automatically. Where should the login data come from?
The solution is simple. Just add the required data to the CI user gradle home directories (e.g. /home/travis/.gradle) gradle.properties file. This way, you can also simply add access right management, by entering the login data of a CI user. Local builds will be published by your local user account (if allowed), CI builds by the CI system.
Appendix
Your question includes the Gradle specific term 'extension', but, to be honest, it got nothing to do with your question. It is correct, that most configuration in Gradle is done via so-called extension objects, that are added to the Project object, but it is an internal term, you do not need to understand it to fix this problem.
Edit: Comment answer
Now I can understand your confusion. Gradle distinguishes between the configuration phase and the execution phase. Nearly everything in your build script is executed during the configuration phase, only task actions (what a task does, e.g. copying, deleting ...), doFirst and doLast closures (so basically tasks) are executed during execution phase. If you define the list of tasks to be executed (via command line), it only affects the execution phase, but your configuration code will be executed at every single build, even if only one independent task is executed afterwards.
To solve this problem, follow the solution in the First block and add your private data to the user-specific Gradle directory gradle.properties file. It will be added to the project object and therefor, it will be accessible from the build file. But, since the file (or the data) does not exist on your CI, accessing it directly will raise an error when building on the CI. You can use the findProperty(propertyName) method as a fail-safe way to access the property value. If the property does not exist, it returns null (in the configuration phase), so no error occurs, as long as you don not execute the bintrayUpload task (which is not your goal on the CI).
Currently, I'm researching about GUI automated testing on Android and for some reason, I need a tool that can generate code coverage report from manual testing.
After a long searching, I found that Jacoco and Emma mention the manual approach on their website.
But unfortunately, There is not any up-to-date-working example on the internet.
I have tried a lot of suggesting solution, for example, https://groups.google.com/forum/#!searchin/jacoco/manual$20android%7Csort:date/jacoco/vx0g_6TKY8Q/0Tg3fX84CAAJ .
It generated a coverage.exec but the file's size was only few byte (of course, Jacoco failed to generate any report from it.)
Here is what I have tried: https://github.com/kindraywind/MyDummy
In app/build.gradle
apply plugin: 'jacoco'
jacoco {
toolVersion ="0.7.8+" //I did try "0.7.4+" as the suggest.
}
task jacocoTestReport(type: JacocoReport) { … }
In jacoco-agent.properties
destfile=/storage/sdcard/coverage.exec
In app/src/main/AndroidManifest.xml`
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
In MainActivity.java
protected void onStop()
{
super.onStop();
if(BuildConfig.DEBUG)
{
String TAG = "jacoco";
try {
String covPath = Environment.getExternalStorageDirectory().getPath() + "/coverage.exec";
File coverageFile = new File(covPath);
Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
Method dumpCoverageMethod = emmaRTClass.getMethod("dumpCoverageData",coverageFile.getClass(), boolean.class, boolean.class);
dumpCoverageMethod.invoke(null, coverageFile, true, false);
} catch (Exception e) {
}
}
}
The emulator is Nexus 5 API 19 (I did try most of the versions.)
The log from device
EMMA: runtime coverage data merged into [/storage/sdcard/coverage.exec] {in 8 ms}
The log after run ./gradlew jacocoTestReport
Unable to read execution data file /Users/MyDummy/app/coverage.exec
I'm using OSX10.12.3 if it related.
To sum up, I need to know (or any working example) how to obtain code coverage while:
Test the app manually.
On Android application.
Which is using Gradle not Maven or Ant.
Android Studio not Eclipse.
I see no way out and would really appreciate a help.
I've provided a detailed how-to guide on how to obtain code coverage during manual testing at my blog. Following it you should obtain a code coverage report. You seem to be headed in the right direction, but please read the post thoroughly.
A bit more advanced and complete solution is described in another blog post. It uses NanoHttpd to create a REST server on the device/emulator. The API provides a single endpoint that writes the report file as a response. Additionally, a custom (much faster) CSV report writer is provided.
Feel free to contact me if you want to discuss GUI automated testing (related to Android) further :)
I keep getting this error (Upgrading old nbandroid project projectName FAILED. See log file for details.) for a few android projects in Netbeans. I'm not sure where to find the log the message refers to, I have checked every log I can find both in netbeans & system logs. To no avail, no more information.
I tried tracking down the score code and see what generates this error, I found this code (here: https://code.google.com/p/nbandroid/source/browse/project/src/org/netbeans/modules/android/project/AndroidProjectUtil.java?name=v1.5beta&r=d12ce88eb7d6a04ac55d0ae2bd8813fea1651bb4)
private static AndroidGeneralData findSDKAndTarget(
AndroidProject project, PropertyProvider props, FileObject nbproject) {
String platformName = props.getProperties().get("platform.active");
if (platformName == null) {
LOG.log(Level.INFO, "Cannot upgrade old nbandroid project. platform definition not found in project.properties");
return null;
}
FileObject storage = FileUtil.getConfigFile(PLATFORM_STORAGE);
String buildTargetPath = null;
if (storage != null) {
for (FileObject platformProvider : storage.getChildren()) {
buildTargetPath = parseIfActivePlatorm(platformProvider, platformName);
if (buildTargetPath != null) {
break;
}
}
}
if (buildTargetPath == null) {
LOG.log(Level.INFO, "Cannot upgrade old nbandroid project. platform {0} not found", platformName);
return null;
}
DalvikPlatform platform = toDalvikPlatorm(buildTargetPath);
if (platform == null) {
LOG.log(Level.INFO, "Cannot upgrade old nbandroid project. platform {0} not found in Android SDK", platformName);
return null;
}
AndroidGeneralData data = new AndroidGeneralData();
data.setPlatform(platform);
data.setProjectDirPath(project.getProjectDirectoryFile().getAbsolutePath());
data.setProjectName(project.getLookup().lookup(ProjectInformation.class).getName());
return data;
}
Leaving pretty much 3 possibilities, I have tried looking for all these, and as far as I can tell the data is present for all 3. I checked the project.properties, genfiles.properties and project.xml files, I would be happy to supply these if necessary.
Any tips or advice would be greatly appreciated, the projects work at the moment, but I would like to get rid of the annoying messages at start up.
I have now managed to track down the exact fault. The log file mentioned was well hidden in the netbeans directories (which had also changed place in netbeans 7.2).
I need the platform files in [netbeans file root]/config/services/platforms/org-netbeans-api-java-Platform
These are no longer available in anyway I can find, I also checked all old developer computers we have.
If someone has these platform files (I suspect they are xml files, from what I found) it would be greatly appreciated if they could send them to me. I should be able to modify them to make them work.
It seems that the project update process failed to load Java Platform definition from a file that is somewhere in your netbeans userdir - http://wiki.netbeans.org/FaqWhatIsUserdir As a result it cannot set Android SDK location and find what is the target platform for your project. It is possible that the file/the settings was lost when you upgraded your IDE or for some other reason.
My suggestion is that you migrate your project manually. There is a hint in http://www.nbandroid.org/2011/02/beta-build-of-new-project-support.html
remove nbproject directory and create an Android project as described in http://developer.android.com/tools/projects/projects-cmdline.html. NBAndroid recognizes this project structure and will be able to work with it. Or create this project in an empty directory and move your sources + resources there.
-Radim
I'm trying to use Android annotations framework because it seems quite powerful. I'm quite stuck to configuring my first project based on it.
I followed every step of the wiki but it doesn't generate any file after a build.
So when I ask for a generated class from the manifest:
<activity android:name=".MyActivity_"
android:label="#string/app_name">
I get an exception:
java.lang.ClassNotFoundException
My activity is exactly the same one as in the wiki:
#EActivity(R.layout.main)
public class MyActivity extends Activity {
#ViewById
EditText myInput;
#ViewById(R.id.myTextView)
TextView textView;
#Click
void myButton() {
String name = myInput.getText().toString();
textView.setText("Hello "+name);
}
}
Any ideas?
EDIT: Just found out a directory ".apt_generated" is made but it's empty after the build.
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker, here : http://code.google.com/p/androidannotations/issues/entry . You could also use the AndroidAnnotations mailing list, http://groups.google.com/group/androidannotations
First, I have a few questions :
Which IDE do you use : Eclipse, Netbeans, IntelliJ ? Which version ?
Do you use Maven, Ant, or only your IDE to build the project ?
Your problem may be due to a few things : annotation processing not triggered, a bug in AA, or the files generated in a folder not part of the classpath.
In Eclipse, you may get more information from the "Window > Show View > Error Log" view. If annotation processing is triggered, you should see some messages about AndroidAnnotations.
For other people who are running into this and the leading answer doesn't work, run a build and then search for the file androidannotations.log somewhere in the project. This log file is generated and may hint at what is wrong.
For me, it had a warning message that it could not locate AndroidManifest.xml. Though this seemed like just a warning, it was actually the cause of the error... Not finding my AndroidManifest.xml file resulted in it not generating some of the classes it should have.
Check if you have the xml file. If not, the solution is obvious. If you do have it, the typical reason AA cannot find the file is because it is in a non-standard location -- AA recursively checks the parent directories above where it generates files for this xml file and will fail if it's not there. In my case, my AndroidManifest.xml was located in [project root]/app/src/main which is not a direct ancestor folder so that was the problem.
You can specify where your xml file is in your project build.gradle:
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = ["androidManifestFile": "specify_location_of_AndroidManifest.xml_here"]
}
}
}
}